Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QT can't find QWidget includes



  • Hi, I'm trying to compile a project on Qt 5.7.1 on a debian distribution however qt can't find Widgets includes. When I checked to previous topics the answer always was to add QT+=Widgets in .pro file but it doesn't change anything on my side.

    I checked that I have the headers qt is looking for but the path is not added either in the .qmake.stash, nor in the Makefile generated.

    Here is a copy-paste of my .pro file :

    TEMPLATE = subdirs
    #CONFIG+=ordered
    QT += Widgets
    SUBDIRS =
    src
    app
    test \

    test.depends = src
    app.depends = src

    OTHER_FILES +=
    default.pri

    Any advices ?



  • @R-griset Hmm, your PRO file seems to be a little strange to me, I would change it like this:

    TEMPLATE = subdirs
    #  You don't need widgets for a subdirs project!!!
    #QT += widgets
    
    # \ is used to continue on next line
    SUBDIRS = \
        src \
        app \
        test
    
    test.depends = src
    app.depends = src
    
    OTHER_FILES += default.pri
    

    I think this should work better, take a look at https://wiki.qt.io/SUBDIRS_-_handling_dependencies for more details.



  • Thanks for your answer, unfortunately I added "QT+=widgets" in order to solve an initial problem. Then here is initial errors when I try to compile with your .pro file :

    In file included from ../../UI_11_05/src/widgets/gantt_view.cpp:1:0:
    ../../UI_11_05/src/widgets/gantt_view.h:4:29: fatal error: QAbstractItemView: Aucun fichier ou dossier de ce type
    #include <QAbstractItemView>
    ^
    compilation terminated.
    In file included from ../../UI_11_05/src/widgets/resource_view.cpp:1:0:
    ../../UI_11_05/src/widgets/resource_view.h:4:29: fatal error: QAbstractItemView: Aucun fichier ou dossier de ce type
    #include <QAbstractItemView>
    ^
    In file included from ../../UI_11_05/src/widgets/central_widget_solution_tab.cpp:1:0:
    ../../UI_11_05/src/widgets/central_widget_solution_tab.h:4:21: fatal error: QComboBox: Aucun fichier ou dossier de ce type
    #include <QComboBox>
    ^
    compilation terminated.
    In file included from ../../UI_11_05/src/widgets/central_widget.cpp:1:0:
    ../../UI_11_05/src/widgets/central_widget.h:4:22: fatal error: QTabWidget: Aucun fichier ou dossier de ce type
    #include <QTabWidget>
    ^
    compilation terminated.
    compilation terminated.
    In file included from ../../UI_11_05/src/widgets/parameters_bar.cpp:1:0:
    ../../UI_11_05/src/widgets/parameters_bar.h:4:23: fatal error: QDockWidget: Aucun fichier ou dossier de ce type
    #include <QDockWidget>
    ^
    compilation terminated.
    /usr/lib/x86_64-linux-gnu/qt5/bin/moc -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I'/home/d07876/Bureau/Ancrage/Code interface graphique ancrage/UI_11_05/src' -I'/home/d07876/Bureau/Ancrage/Code interface graphique ancrage/UI_11_05/src' -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I/usr/include/c++/6 -I/usr/include/x86_64-linux-gnu/c++/6 -I/usr/include/c++/6/backward -I/usr/lib/gcc/x86_64-linux-gnu/6/include -I/usr/local/include -I/usr/lib/gcc/x86_64-linux-gnu/6/include-fixed -I/usr/include/x86_64-linux-gnu -I/usr/include ../../UI_11_05/src/widgets/sidebar.h -o moc_sidebar.cpp
    In file included from ../../UI_11_05/src/widgets/solution_pool_view.cpp:1:0:
    ../../UI_11_05/src/widgets/solution_pool_view.h:4:29: fatal error: QAbstractItemView: Aucun fichier ou dossier de ce type
    #include <QAbstractItemView>
    ^
    compilation terminated.
    In file included from ../../UI_11_05/src/widgets/mainwindow.cpp:1:0:
    ../../UI_11_05/src/widgets/mainwindow.h:4:24: fatal error: QApplication: Aucun fichier ou dossier de ce type
    #include <QApplication>
    ^
    compilation terminated.
    In file included from ../../UI_11_05/src/widgets/sidebar_list.cpp:1:0:
    ../../UI_11_05/src/widgets/sidebar_list.h:4:21: fatal error: QTreeView: Aucun fichier ou dossier de ce type
    #include <QTreeView>
    ^
    compilation terminated.
    In file included from ../../UI_11_05/src/widgets/sidebar.cpp:1:0:
    ../../UI_11_05/src/widgets/sidebar.h:4:23: fatal error: QDockWidget: Aucun fichier ou dossier de ce type
    #include <QDockWidget>
    ^
    compilation terminated.
    In file included from ../../UI_11_05/src/widgets/parameters_edition_dialog.cpp:1:0:
    ../../UI_11_05/src/widgets/parameters_edition_dialog.h:4:19: fatal error: QDialog: Aucun fichier ou dossier de ce type
    #include <QDialog>


  • Lifetime Qt Champion

    @R-griset said in QT can't find QWidget includes:

    Thanks for your answer, unfortunately I added "QT+=widgets" i

    You should add this line in the pro file in your subdirs where you're using widgets.



  • @R-griset I think you have misunderstood something, QT += widgets should be added in the application and library projects in which the widgets are used. Maybe the app project (app.pro)?



  • Yes I didn't get it was in my app.pro file, unfortunately this line is already in this file, here is the app.pro file :

    include(../default.pri)

    QT += widgets

    QMAKE_CXXFLAGS += -std=c++0x

    QMAKE_LFLAGS_RPATH =
    QMAKE_LFLAGS = -Wl,-rpath,"'$$ORIGIN/../src'",--enable-new-dtags

    CONFIG -= app_bundle
    CONFIG += qtc_runnable
    #QT += serialport

    TEMPLATE = app

    SOURCES += main.cpp

    LIBS += -L../src -lmyapp


  • Lifetime Qt Champion

    @R-griset The errors seem to come from src subdirectory - did you add widgets there?



  • I noticed that just after my answer and indeed it solves this problem (still it doesn't compile but I need to check the new errors)
    Thanks a lot for your help


  • Lifetime Qt Champion

    @R-griset The please mark this topic as solved, thx.


Log in to reply