错误:“命名空间”之前需要声明说明符;
文件名:widgets.c
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
return app.exec();
}
Pro 文件:
anisha@linux-dopx:~/Desktop/notes/qt> cat qt.pro
######################################################################
# Automatically generated by qmake (2.01a) Thu Sep 22 14:53:10 2011
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
SOURCES += widgets.c
anisha@linux-dopx:~/Desktop/notes/qt>
错误消息:
anisha@linux-dopx:~/Desktop/notes/qt> make
gcc -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I../../../qtsdk-2010.05/qt/mkspecs/linux-g++-64 -I. -I../../../qtsdk-2010.05/qt/include/QtCore -I../../../qtsdk-2010.05/qt/include/QtGui -I../../../qtsdk-2010.05/qt/include -I. -I. -o widgets.o widgets.c
In file included from ../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:45:0,
from ../../../qtsdk-2010.05/qt/include/QtCore/qobject.h:47,
from ../../../qtsdk-2010.05/qt/include/QtCore/qabstractanimation.h:45,
from ../../../qtsdk-2010.05/qt/include/QtCore/QtCore:3,
from ../../../qtsdk-2010.05/qt/include/QtGui/QtGui:3,
from widgets.c:12:
../../../qtsdk-2010.05/qt/include/QtCore/qnamespace.h:51:1: warning: return type defaults to ‘int’
../../../qtsdk-2010.05/qt/include/QtCore/qnamespace.h: In function ‘QT_MODULE’:
../../../qtsdk-2010.05/qt/include/QtCore/qnamespace.h:54:1: error: expected declaration specifiers before ‘namespace’
../../../qtsdk-2010.05/qt/include/QtCore/qnamespace.h:1775:1: error: expected declaration specifiers before ‘Q_DECLARE_OPERATORS_FOR_FLAGS’
../../../qtsdk-2010.05/qt/include/QtCore/qnamespace.h:1796:1: error: expected declaration specifiers before ‘class’
../../../qtsdk-2010.05/qt/include/QtCore/qnamespace.h:1851:2: error: expected declaration specifiers before ‘;’ token
In file included from ../../../qtsdk-2010.05/qt/include/QtCore/qobject.h:47:0,
from ../../../qtsdk-2010.05/qt/include/QtCore/qabstractanimation.h:45,
from ../../../qtsdk-2010.05/qt/include/QtCore/QtCore:3,
from ../../../qtsdk-2010.05/qt/include/QtGui/QtGui:3,
from widgets.c:12:
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:51:1: error: expected declaration specifiers before ‘QT_MODULE’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:55:1: error: expected declaration specifiers before ‘class’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:142:1: error: expected declaration specifiers before ‘template’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:145:1: error: expected declaration specifiers before ‘template’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:212:1: error: expected declaration specifiers before ‘Q_CORE_EXPORT’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:240:1: error: expected declaration specifiers before ‘class’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:241:1: error: expected declaration specifiers before ‘class’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:242:1: error: expected declaration specifiers before ‘class’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:243:1: error: expected declaration specifiers before ‘class’
我在这里错过了什么?
File name: widgets.c
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
return app.exec();
}
Pro file:
anisha@linux-dopx:~/Desktop/notes/qt> cat qt.pro
######################################################################
# Automatically generated by qmake (2.01a) Thu Sep 22 14:53:10 2011
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
# Input
SOURCES += widgets.c
anisha@linux-dopx:~/Desktop/notes/qt>
Error messages:
anisha@linux-dopx:~/Desktop/notes/qt> make
gcc -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I../../../qtsdk-2010.05/qt/mkspecs/linux-g++-64 -I. -I../../../qtsdk-2010.05/qt/include/QtCore -I../../../qtsdk-2010.05/qt/include/QtGui -I../../../qtsdk-2010.05/qt/include -I. -I. -o widgets.o widgets.c
In file included from ../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:45:0,
from ../../../qtsdk-2010.05/qt/include/QtCore/qobject.h:47,
from ../../../qtsdk-2010.05/qt/include/QtCore/qabstractanimation.h:45,
from ../../../qtsdk-2010.05/qt/include/QtCore/QtCore:3,
from ../../../qtsdk-2010.05/qt/include/QtGui/QtGui:3,
from widgets.c:12:
../../../qtsdk-2010.05/qt/include/QtCore/qnamespace.h:51:1: warning: return type defaults to ‘int’
../../../qtsdk-2010.05/qt/include/QtCore/qnamespace.h: In function ‘QT_MODULE’:
../../../qtsdk-2010.05/qt/include/QtCore/qnamespace.h:54:1: error: expected declaration specifiers before ‘namespace’
../../../qtsdk-2010.05/qt/include/QtCore/qnamespace.h:1775:1: error: expected declaration specifiers before ‘Q_DECLARE_OPERATORS_FOR_FLAGS’
../../../qtsdk-2010.05/qt/include/QtCore/qnamespace.h:1796:1: error: expected declaration specifiers before ‘class’
../../../qtsdk-2010.05/qt/include/QtCore/qnamespace.h:1851:2: error: expected declaration specifiers before ‘;’ token
In file included from ../../../qtsdk-2010.05/qt/include/QtCore/qobject.h:47:0,
from ../../../qtsdk-2010.05/qt/include/QtCore/qabstractanimation.h:45,
from ../../../qtsdk-2010.05/qt/include/QtCore/QtCore:3,
from ../../../qtsdk-2010.05/qt/include/QtGui/QtGui:3,
from widgets.c:12:
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:51:1: error: expected declaration specifiers before ‘QT_MODULE’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:55:1: error: expected declaration specifiers before ‘class’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:142:1: error: expected declaration specifiers before ‘template’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:145:1: error: expected declaration specifiers before ‘template’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:212:1: error: expected declaration specifiers before ‘Q_CORE_EXPORT’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:240:1: error: expected declaration specifiers before ‘class’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:241:1: error: expected declaration specifiers before ‘class’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:242:1: error: expected declaration specifiers before ‘class’
../../../qtsdk-2010.05/qt/include/QtCore/qobjectdefs.h:243:1: error: expected declaration specifiers before ‘class’
What's the point that I am missing here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您正在使用 C 编译器来编译 C++。尝试将文件重命名为 widgets.cpp。
Looks like you are using the C Compiler to compile C++. Try renaming your file to widgets.cpp.