Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-26170

Use new CMake QML API (Qt 6.2) in Qt Creator wizards

    XMLWordPrintable

Details

    Description

      Qt 6.2 features a new CMake API to define projects using QML: qt_add_qml_module. We should support this new API in all Qt Quick wizards that support CMake.

      This is also an opportunity to greatly simplify the wizard content, by relying
      a) on Qt 6.2
      b) on a recent CMake version (suggestion: 3.16)

      Qt Quick Minimal Wizard

      When selecting a 'Qt Quick App - empty' the minimal supported Qt version' dialog should feature "Qt 6.2" (can replace "Qt 6"). When selecting this, the file template should look like the following:

      CMakeLists.txt
      cmake_minimum_required(VERSION 3.16)
      
      project(myapp VERSION 0.1 LANGUAGES CXX)
      
      set(CMAKE_AUTOMOC ON)
      set(CMAKE_CXX_STANDARD 17)
      set(CMAKE_CXX_STANDARD_REQUIRED ON)
      
      find_package(Qt6 6.2 COMPONENTS Quick REQUIRED)
      
      qt_add_executable(myapp
          main.cpp
      )
      
      qt_add_qml_module(myapp
          URI myapp
          VERSION 1.0
          QML_FILES main.qml
      )
      
      target_compile_definitions(myapp
          PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
      target_link_libraries(myapp
          PRIVATE Qt6::Quick)
      
      main.cpp
      #include <QGuiApplication>
      #include <QQmlApplicationEngine>
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
      
          QQmlApplicationEngine engine;
          const QUrl url(u"qrc:/myapp/main.qml"_qs);
          QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                           &app, [url](QObject *obj, const QUrl &objUrl) {
              if (!obj && url == objUrl)
                  QCoreApplication::exit(-1);
          }, Qt::QueuedConnection);
          engine.load(url);
      
          return app.exec();
      }
      
      main.qml
      import QtQuick
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      }
      

      Other wizards should be handled similarly.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              artem.sokolovskii Artem Sokolovskii
              kkohne Kai Köhne
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes