我的主目录中有一个目录为qt-everywhere-opensource-src-4.8.2。 这个目录包含基本的QT包,但问题是,当我编译主目录中存在的普通Qt文件时,它显示错误,即找不到相应的QT包。但是,当我尝试编译正常的c文件时g ++和c ++文件由g ++然后它没有给出错误。 我想要的是知道如何包含目录中的那些包。 我想编译的文件是: -
#include <QApplication>
#include <QWidget>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.resize(250, 150);
window.setWindowTitle("Simple example");
window.show();
return app.exec();
}
错误=
demo.cpp:1:24: error: QApplication: No such file or directory
demo.cpp:2:19: error: QWidget: No such file or directory
demo.cpp: In function âint main(int, char**)â:
demo.cpp:6: error: âQApplicationâ was not declared in this scope
demo.cpp:6: error: expected â;â before âappâ
demo.cpp:8: error: âQWidgetâ was not declared in this scope
demo.cpp:8: error: expected â;â before âwindowâ
demo.cpp:10: error: âwindowâ was not declared in this scope
demo.cpp:14: error: âappâ was not declared in this scope
答案 0 :(得分:1)
您应该将此行添加到.pro文件中:
QT += core gui