I want to compile Qt example. I get error QtWidgets: No such file or directory #include
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - does not help
QT += widgets - does not help
INCLUDEPATH += /opt/Qt/5.3/Src/qtbase/include/ - does not help
Qt 5.3. Ubuntu 14.04 x64.
You need to double check that you completed all these steps:
Module installed
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
You re-run the Qt 5 qmake.
Having said that, I would like to remind you that including the whole module is not a good idea as it includes all the widgets related things. Try to narrow it down to the headers that you really need.
As you noticed Qt directory structure changed between Qt4 and Qt5. QWidget header moved to a QtWidgets directory. Try adding
INCLUDEPATH += /opt/Qt/5.3/Src/qtbase/include/QtWidgets
If that does not help try finding the header manually using
find /opt/Qt/5.3/Src/qtbase/ -name QWidget
and and the directory it is in to INCLUDEPATH
Edit based on comment from Final Contest.
I agree that workarounds usually are a bad idea. To test where QT your installation looks for qt5 headers and libraries. Create a minimal project.
#include <QApplication>
#include <QtWidgets>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget w;
w.show();
app.exec();
}
Generate a project and add QT += widget
/opt/Qt/5.3/Src/qtbase/bin/qmake -project
Project file
######################################################################
# Automatically generated by qmake (3.0) Thu Jul 10 13:05:17 2014
######################################################################
TEMPLATE = app
TARGET = so_qtwidgets
INCLUDEPATH += .
QT += widgets
# Input
SOURCES += main.cpp
Generate a make file
/opt/Qt/5.3/Src/qtbase/bin/qmake
The interesting parts widget flag adds:
The only part which should differ is the paths to QtWidgets and QtGui. If these a wrong the I would try reinstalling Qt.
Check what your .pro file looks like before you run "make". I found that the command "qmake -project" auto generated a .pro file that caused this same error. I now compiled my qt project via the following commands and the error went away:
qmake my_project.pro
make
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With