Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Kit v5.15 Desktop Application with CMake: 'QApplication' file not found
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

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 627 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Developer123
    wrote on last edited by
    #1

    I created a new project on Qt Creator going to: File > New Project > Application (QT) > Qt Quick Application, and chose to use CMake. On main.cpp I put:

    #include <QQmlApplicationEngine>
    #include <QApplication>
    #include <QQmlContext>
    
    int main(int argc, char *argv[])
    {
    }
    

    All includes work, except for #include <QApplication>. I tried adding find_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
    ...
    
    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Do you want to make a QML or Widgets application? Qt Quick Application is a QML app, while QApplication is 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).

      1 Reply Last reply
      1
      • M Offline
        M Offline
        mchinand
        wrote on last edited by mchinand
        #3

        You also need to include the Qt modules to your target_link_libaries() statement:

        target_link_libraries(${PROJECT_NAME} Qt5::Widgets)

        See https://doc.qt.io/qt-5/cmake-get-started.html

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved