QApplication:没有这样的文件或目录
我在 /usr/programs/qt 中安装了 QT4 Creator ,我添加到 PATH /usr/programs/qt/bin , QTDIR=/usr/programs/qt,LD_LIBRARY_PATH=$QTDIR/lib,也用于 MANPATH 和导出。问题是演示示例工作正常,但是当我在其他目录(例如 /home/Jane/)中创建新项目时,它不起作用,我收到如下错误
/home/Jane/test-build-desktop/../test/main.cpp:1: 错误:QApplication:没有这样的文件或 目录 /home/Jane/test-build-desktop/../test/main.cpp:2: 错误:QLabel:没有这样的文件或 目录
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
return app.exec();
}
有人可以帮助我吗?
I installed QT4 Creator in /usr/programs/qt , I add to PATH /usr/programs/qt/bin,
QTDIR=/usr/programs/qt,LD_LIBRARY_PATH=$QTDIR/lib, and also for MANPATH and export. Problem is that demo examples work fine, but when I create new project in other directory for example /home/Jane/ it doesn't work, I got errors like
/home/Jane/test-build-desktop/../test/main.cpp:1:
error: QApplication: No such file or
directory
/home/Jane/test-build-desktop/../test/main.cpp:2:
error: QLabel: No such file or
directory
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
label->show();
return app.exec();
}
Can anybody help me ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
添加到您的 .pro 文件:
Add to your .pro file:
我有同样的问题。在我的“.pro”文件中,
然后我将其更改为
,问题就解决了
I've the same problem. in my ".pro" file it was
then I changed it to
and the problem solved
尝试在您的 .pro 文件中添加
QT += 小部件
。我有同样的消息...看起来基于 5.0 Qt 的应用程序默认不喜欢小部件...
try to add
QT += widgets
at your .pro file. I had the same message... It looks like from 5.0 Qt-based applications does not like widgets by default...
该解决方案适用于我,Qt 5.7
将以下行添加到您的 .pro 文件后:
右键单击您的 Qt 项目,然后单击“运行 qmake”
运行 qmake
之后,当您重新编译项目时,一切都应该没问题。
The solution works for me, Qt 5.7
After added the following line to your .pro file:
Right-click on your Qt Project and click "Run qmake"
Run qmake
After this when you re-complie your project, everything should be fine.
如果您的 .pro 文件有此行:
您需要将其删除。它告诉您要从您的应用程序中删除 gui 模块。
您可以通过键入来启用它,
但实际上不需要它,因为默认情况下启用了 gui 模块。
If your .pro file has this line:
you need to delete it. It tells that the gui module to be removed from your app.
You can enable it by typing
but actually it is not needed since the gui module is enabled by default.
对于 Ubuntu 14.04,如果遇到相同的错误:
尝试
qmake-qt4
,然后make
。当然,如果不存在,您可以使用以下命令获取所有 QT4 库:For Ubuntu 14.04 if you get the same error:
Try
qmake-qt4
and thenmake
. Of course you can get all the QT4 libraries if its not present using: