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.
-
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.
-
I have the same issue but now with Qt6.
- OS: Ubuntu 24.0.1
- Qt: Creator 6.7.3
- Compiler: gcc/g++ 13.2
- IDE: MS Visual Studio Code (from snap)
- Extensions installed in MVSC: ms-vscode.cpptools, twxs.cmake, ms-vscode.cmake-tools, theqtcompany.qt, theqtcompany.qt-cpp-pack and tonka3000.qtvsctools
- Qt's installation folder: home/Qt/
- Qt example's folder: home/Qt/Examples/Qt-6.7.3/widgets/widgets/calculator/
I'm trying to run this example using CMakeLists.txt and c_cpp_properties.json.
c_cpp_properties.json in .vscode:{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**", "/home/arantxa/Qt/6.7.3/gcc_64/include/**", "/home/arantxa/Qt/6.7.3/gcc_64/include/QtWidgets/" ], "defines": [], "compilerPath": "/usr/bin/gcc", "cStandard": "c17", "cppStandard": "gnu++17", "intelliSenseMode": "linux-gcc-x64" } ], "version": 4 }
The top-level CMakeLists.txt:
# Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause cmake_minimum_required(VERSION 3.16) project(calculator LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) qt_standard_project_setup() qt_add_executable(calculator button.cpp button.h calculator.cpp calculator.h main.cpp ) set_target_properties(calculator PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) target_link_libraries(calculator PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets ) install(TARGETS calculator BUNDLE DESTINATION . RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) qt_generate_deploy_app_script( TARGET calculator OUTPUT_SCRIPT deploy_script NO_UNSUPPORTED_PLATFORM_ERROR ) install(SCRIPT ${deploy_script})
Everything that is required, every include, is listed! I'm not sure what should I do.