QApplication:没有这样的文件或目录

发布于 2024-10-18 14:37:20 字数 666 浏览 2 评论 0原文

我在 /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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

月亮是我掰弯的 2024-10-25 14:37:20

添加到您的 .pro 文件:

QT += gui

Add to your .pro file:

QT += gui
·深蓝 2024-10-25 14:37:20

我有同样的问题。在我的“.pro”文件中,

QT -= gui

然后我将其更改为

QT += gui

,问题就解决了

I've the same problem. in my ".pro" file it was

QT -= gui

then I changed it to

QT += gui

and the problem solved

疑心病 2024-10-25 14:37:20
QApplication: No such file or directory ...

尝试在您的 .pro 文件中添加

QT += 小部件

。我有同样的消息...看起来基于 5.0 Qt 的应用程序默认不喜欢小部件...

QApplication: No such file or directory ...

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...

浸婚纱 2024-10-25 14:37:20

该解决方案适用于我,Qt 5.7

将以下行添加到您的 .pro 文件后:

QT += widgets

右键单击您的 Qt 项目,然后单击“运行 qmake”

运行 qmake

之后,当您重新编译项目时,一切都应该没问题。

The solution works for me, Qt 5.7

After added the following line to your .pro file:

QT += widgets

Right-click on your Qt Project and click "Run qmake"

Run qmake

After this when you re-complie your project, everything should be fine.

木緿 2024-10-25 14:37:20

如果您的 .pro 文件有此行:

QT       -= gui

您需要将其删除。它告诉您要从您的应用程序中删除 gui 模块。

您可以通过键入来启用它,

QT       += gui

但实际上不需要它,因为默认情况下启用了 gui 模块。

If your .pro file has this line:

QT       -= gui

you need to delete it. It tells that the gui module to be removed from your app.

You can enable it by typing

QT       += gui

but actually it is not needed since the gui module is enabled by default.

空名 2024-10-25 14:37:20

对于 Ubuntu 14.04,如果遇到相同的错误:

ABC$ make
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I. -I. -I/usr/include/qt5 -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -o textpad.o textpad.cpp
textpad.cpp:1:24: fatal error: QApplication: No such file or directory
 #include <QApplication>
                        ^
compilation terminated.
make: *** [textpad.o] Error 1

尝试 qmake-qt4,然后 make。当然,如果不存在,您可以使用以下命令获取所有 QT4 库:

sudo apt-get install libqt4-dev 

For Ubuntu 14.04 if you get the same error:

ABC$ make
g++ -c -m64 -pipe -O2 -Wall -W -D_REENTRANT -fPIE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I. -I. -I/usr/include/qt5 -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtCore -I. -o textpad.o textpad.cpp
textpad.cpp:1:24: fatal error: QApplication: No such file or directory
 #include <QApplication>
                        ^
compilation terminated.
make: *** [textpad.o] Error 1

Try qmake-qt4 and then make. Of course you can get all the QT4 libraries if its not present using:

sudo apt-get install libqt4-dev 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文