Qt 5.3. QtWidgets: No such file or directory #include <QtWidgets>
Solution 1
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.
Solution 2
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:
- In my case -I/usr/include/qt5/QtWidgets -I/usr/include/qt5/QtGui to INCPATH
- -DQT_WIDGETS_LIB to DEFINES variable.
- -lQt5Widgets -lQt5Gui to libs.
The only part which should differ is the paths to QtWidgets and QtGui. If these a wrong the I would try reinstalling Qt.
Solution 3
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
Ufx
Updated on July 19, 2022Comments
-
Ufx almost 2 years
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.
-
Ufx almost 10 yearsNarrowing it down is working. But I want to learn how compile applications which have to compile.-Module installed and -You re-run the Qt 5 qmake. How can I check it?
-
László Papp almost 10 years@Ufx: run /opt/Qt/5.3/Src/qtbase/bin/qmake ... or just click on the corresponding context menu option in QtCreator.
-
Ufx almost 10 yearsThere is remain to check 'Module installed'. How can I check it?
-
Ufx almost 10 yearsThe directory exists.
-
Ufx almost 10 yearsIt helps with that error. But now is new error: QtWidgets/QtWidgetsDepends: No such file or directory #include <QtWidgets/QtWidgetsDepends>. I think I understood what do I need to do. But why are official examples need in editing? May be there is way to include all qt directories in the environment settings?
-
Tobias almost 10 yearsAre you certain /opt/Qt/5.3/Src/qtbase points to the installed qt library? I would not expect Src in that path. On fedora 20 the path is /usr/include/qt5/QtWidgets/. I don't know why there are bugs in Qt's documentation. This is how I solved it.
-
László Papp almost 10 yearsIt is difficult to explain because you are lacking the basics. No, you should not check /opt/Qt/5.3/Src/qtbase/include itself, but whether it has the QtWidgets directory in there...
-
László Papp almost 10 yearsIt is a bad idea to specify the include path explicitly.
QT+=widgets
exists for this reason. Furthermore, the OP is not usingQWidget header
, butQtWidgets
. I think you are confused. Furthermore, even if you do that manual include workaround, you will still have the aforementioned problem which would lead to include another path, etc. -
Tobias almost 10 yearsAdded a minimal widget application to help check qt installation.