QT5.0.1在Windows上 出现QApplication: No such file or directory 有关问题的解决方法
QT5.0.1在Windows下 出现QApplication: No such file or directory 问题的解决办法
HelloWorld.cpp代码如下:
最近在Windows7下安装了最新的Qt5.0.1的Windows安装包,可以到QT官网http://qt-project.org/downloads,该版本集成了Qt5.0.1库、MinGW4.7编译器、Qt Creator 2.6.2,貌似解决了以前Qt Creator不能正常使用MinGW编译器的问题。下载后默认安装就OK了,不过安装后居然有3.68G的文件,比VS2012多不少。
测试一下HelloWorld程序,首先在Qt Creator中打开菜单【文件】->【新建文件或项目】(或直接Ctrl+N),选择【其他项目】->【空的QT项目】,取名为HelloWorld,然后再往工程里面添加一个HelloWorld.cpp的C++源文件。
#include <QApplication> #include <QPushButton> #include <QLabel> #include <QHBoxLayout> int main(int argc, char **argv) { QApplication app(argc, argv); QWidget *pMainWidget = new QWidget; QHBoxLayout *pBoxLayout = new QHBoxLayout; QLabel *pLabel = new QLabel(pMainWidget); pLabel->setText("Hello World!"); QPushButton *pQuitButton = new QPushButton(pMainWidget); pQuitButton->setText("Quit Qt!"); pBoxLayout->addWidget(pLabel); pBoxLayout->addWidget(pQuitButton); QSize windowSize(300,200); pMainWidget->resize(windowSize); pMainWidget->show(); QObject::connect(pQuitButton,SIGNAL(clicked()),pMainWidget,SLOT(close())); return app.exec(); }
运行之后出现以下错误:QApplication: No such file or directory,估计是相应的QApplication对应的库文件找不到。
上网查了一大通,基本都是Linux ubuntu等版本下的解决方案,如下****博客:http://blog.****.net/apple1985507/article/details/5435358;找了半天在这篇新浪博客找到了答案:
http://blog.sina.com.cn/s/blog_9da24f3b0101epan.html
解决方法是:在HelloWorld.pro工程项目文件中添加一行QT += widget,然后再编译运行就OK了。