错误:“命名空间”之前需要声明说明符;

发布于 2024-12-05 15:40:03 字数 3519 浏览 0 评论 0原文

文件名: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゞ花落谁相伴 2024-12-12 15:40:03

看起来您正在使用 C 编译器来编译 C++。尝试将文件重命名为 widgets.cpp。

Looks like you are using the C Compiler to compile C++. Try renaming your file to widgets.cpp.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文