文件名:widgets.c
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
return app.exec();
}
专业档案:
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’
我在这里错过了什么意思?
答案 0 :(得分:5)
看起来您正在使用C编译器来编译C ++。尝试将文件重命名为widgets.cpp。