QApplication: No such file or directory
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 director开发者_Python百科y 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 ?
Add to your .pro file:
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
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...
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.
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.
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
精彩评论