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

QApplication: No such file or directory



  • I have appropriately added QtWidgets to my CMakeLists.txt file but when I run make, it throws back the above-mentioned error. Everything works perfectly fine when I try the same with QGuiApplication though. Attaching the header file where I include QApplication (It works perfectly fine when I don't include QApplication). I don't understand where I am going wrong. Appreciate any help!

    #ifndef IGNITION_GUI_QT_H_
    #define IGNITION_GUI_QT_H_
    
    #ifndef _MSC_VER
    #pragma GCC system_header
    #endif
    
    #include <QtCore>
    #include <QtGui>
    
    #include <QGuiApplication>
    #include <QApplication>
    
    #include <QOffscreenSurface>
    #include <QOpenGLFunctions>
    
    #include <QQmlApplicationEngine>
    #include <QQmlComponent>
    #include <QQmlContext>
    #include <QQmlEngine>
    
    #include <QQuickItem>
    #include <QQuickStyle>
    #include <QQuickWindow>
    
    #include <QSGSimpleTextureNode>
    #include <QStandardItemModel>
    
    
    #endif  // IGNITION_GUI_QT_H_
    


  • There seems to be a problem with QtGui. As it cannot seem to locate QtGui either.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What version of Qt ?
    What version of cmake ?
    How did you install both ?
    What OS ?
    What is the content of your CMakeList.txt ?



  • Hi, thanks for welcoming me!
    Apologies for not sharing the information in the post.
    Qt version 5.9.5
    cmake version 3.10.2
    I installed them using apt-get (used qt5-default)
    I'm running Ubuntu Bionic
    My CMakeLists.txt:

    include_directories(
      ${Qt5Core_INCLUDE_DIRS}
      ${Qt5Widgets_INCLUDE_DIRS}
      ${tinyxml_INCLUDE_DIRS}
      ${Qt5Qml_INCLUDE_DIRS}
      ${Qt5Quick_INCLUDE_DIRS}
      ${Qt5QuickControls2_INCLUDE_DIRS}
    )
    
    set (CMAKE_AUTOMOC ON)
    
    add_definitions(
      ${Qt5Core_DEFINITIONS}
      ${Qt5Widgets_DEFINITIONS}
      ${Qt5Qml_DEFINITIONS}
      ${Qt5Quick_DEFINITIONS}
      ${Qt5QuickControls2_DEFINITIONS}
    )
    
    set (qt_headers
      Application.hh
      Dialog.hh
      MainWindow.hh
      Plugin.hh
    )
    
    set (headers
      Conversions.hh
      DragDropModel.hh
      Enums.hh
      Helpers.hh
      ign.hh
      qt.h
      SearchModel.hh
      System.hh
    )
    
    set (resources resources.qrc)
    
    QT5_WRAP_CPP(headers_MOC ${qt_headers})
    QT5_ADD_RESOURCES(resources_RCC ${resources})
    
    ign_create_core_library(SOURCES
      ${sources}
      ${headers_MOC}
      ${resources_RCC}
      CXX_STANDARD 17
    )
    
    target_link_libraries(${PROJECT_LIBRARY_TARGET_NAME}
      PUBLIC
        ${IGNITION-COMMON_LIBRARIES}
        ${IGNITION-MATH_LIBRARIES}
        ${IGNITION-MSGS_LIBRARIES}
        ignition-plugin${IGN_PLUGIN_VER}::loader
        ${IGNITION-TRANSPORT_LIBRARIES}
        ${Qt5Core_LIBRARIES}
        ${Qt5Widgets_LIBRARIES}
        ${Qt5Qml_LIBRARIES}
        ${Qt5Quick_LIBRARIES}
        ${Qt5QuickControls2_LIBRARIES}
        TINYXML2::TINYXML2
    )
    
    add_subdirectory(plugins)
    
    ign_install_all_headers(EXCLUDE_DIRS plugins)
    

    Please let me know in case more info. is needed. Thanks!



  • Solved the issue. I had not added Qt5Widgets to find_package in a top-level CMakeLists.txt.


Log in to reply