先上代码
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
QLabel *tip = new QLabel("Hello World!");
tip->show();
return app.exec();
}
编译
qmake -project
qmake 1.pro
ls
make
报错
g++ -c -pipe -O2 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -isystem /usr/include/qt -isystem /usr/include/qt/QtGui -isystem /usr/include/qt/QtCore -I. -isystem /usr/include/libdrm -I/usr/lib/qt/mkspecs/linux-g++ -o HelloWorld.o HelloWorld.cpp
HelloWorld.cpp:1:24: 致命错误:QApplication:没有那个文件或目录
#include <QApplication>
^
编译中断。
make: *** [Makefile:659:HelloWorld.o] 错误 1
需要在 pro文件中添加
QT += widgets
或者
//qt4: #include <QtGui/QApplication> //qt5: #include <QtWidget/QApplication>