Qt 6.11 is out! See what's new in the release
blog
Qt Kit v5.15 Desktop Application with CMake: 'QApplication' file not found
-
I created a new project on Qt Creator going to:
File > New Project > Application (QT) > Qt Quick Application, and chose to useCMake. Onmain.cppI put:#include <QQmlApplicationEngine> #include <QApplication> #include <QQmlContext> int main(int argc, char *argv[]) { }All includes work, except for
#include <QApplication>. I tried addingfind_package(Qt5Widgets), as explained here, but did not work:#CmakeLists.txt cmake_minimum_required(VERSION 3.14) project(GMA2 VERSION 0.1 LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 Qt5 COMPONENTS Core Quick REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Quick REQUIRED) find_package(Qt5Widgets) set(PROJECT_SOURCES ... -
Do you want to make a QML or Widgets application?
Qt Quick Applicationis a QML app, whileQApplicationis a widgets object. If you want QML don't use QApplication. If you want widgets add them in the components section i.e.find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets REQUIRED). -
You also need to include the Qt modules to your target_link_libaries() statement:
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)