各位前辈好! 我是Qt初学者,遇到一些问题,所以上来请教一下:windows xp + qt-windows-opensource-5.0.1-mingw47_32-x86-offline.exe源代码:#include <QCoreApplication>#include <QPushButton>int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); QPushButton pushButton(QObject::tr("Hello Qt!"));
pushButton.show();
QObject::connect(&pushButton,SIGNAL((clicked()),&a,SLOT(quit()); return a.exec();
}保存为 HelloQt.cpp 后,使用cmd 开始编译:qmake -project
//OK
qmake HelloQt.pro//OK
mingw32-make.exe
>
mingw32-make.exe -f Makefile.Release
mingw32-make.exe[1]: Entering directory 'E:/QtCode/HelloQt'g++ -c -pipe -fno-keep-inline-dllexport -O2 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_OPENGL_ES_2 -DQT
_OPENGL_ES_2_ANGLE -DQT_NEEDS_QMAIN -I. -I"." -I"D:\Qt\Qt5.0.1\5.0.1\mingw47_32\include" -I"D:\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtGui" -I"D:\Qt\Qt5.0.1\5.0.1\mingw47_32\include\QtCore" -I"release" -I"D:\Qt\Qt5.0.1\5.0.1\mingw47_32\mkspec
s\win32-g++" -o release\main.o main.cppmain.cpp:2:23: **fatal error: QPushButton: No such file or directory**
compilation terminated.
Makefile.Release:175: recipe for target 'release/main.o' failed
mingw32-make.exe[1]: *** [release/main.o] Error 1mingw32-make.exe[1]: Leaving directory 'E:/QtCode/HelloQt'makefile:34: recipe for target 'release' failed
mingw32-make.exe: *** [release] Error 2求教各位前辈~
1 回答
饮歌长啸
TA贡献1951条经验 获得超3个赞
主要是:
Qt5的qapplication在QtWidgets模块里,和Qt4不一样,Qt4的qapplication在QtGui模块里。
故而只需在.pro文件中加入:
QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgets
这两行即可。
- 1 回答
- 0 关注
- 176 浏览
添加回答
举报
0/150
提交
取消