Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-100852

How to guides for working with CMake / transitioning from QMake

    XMLWordPrintable

Details

    Description

      With the introduction of Qt 6.2, there are notable changes, specifically in the use of CMake and QML. These are partially covered in recent blog articles, but unfortunately there are also significant holes that leave even an experienced Qt 5 coder (who is a CMake novice) in the lurch.

       

      Example

      In Qt 5, I have previously created C++ classes to extend QML.

      I have struggled to make the transition to Qt 6.2. Between the videos, documentation and recent blog articles, it is possible to learn that the recommended approach is to:

      • use QML_ELEMENT in the class
      • avoid using qmlRegisterType (in main.cpp)
      • avoid creating qmldir manually
      • use qt_add_qml_module in CMakeLists.txt

      but the how-to instructions are incomplete and there are no examples.

      Looking at Qt Creator's Qt 6.2 examples, there is the 'adding' example, which shows the use of QML_ELEMENT, but the project uses qmake not CMake.

      Between the QtWS21 videos introducing the new approach, documentation at https://doc-snapshots.qt.io/qt6-6.2/qt-add-qml-module.html and blog articles https://www.qt.io/blog/qml-modules-in-qt-6.2 & https://www.qt.io/blog/introduction-to-the-qml-cmake-api certain cases are covered, but not this one.

      In the end my solution came via Qt Forum https://forum.qt.io/topic/133341/qt-6-2-cmake-extending-qml-with-a-c-class though this initially remained unanswered for more than a week and it has taken another week to tease the solution out. This suggests that the solution is not widely known or adopted by the community yet.

       

      A request not a rant

      I've written this request having struggled, unable to progress for 2 weeks and sinking 14 hours unproductive time, with one particular blocking issue. I anticipate there may be others ahead.

      I don't want this to be a rant, but rather a request for greater, fully-rounded support, on the forum and in documentation, to help us make the transition to these newer better tools and approaches. I'm excited about using Qt 6.2 and I don't want to be held back!

       

      Attachments

        Issue Links

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

          Activity

            People

              qtbuildsystem Qt Build System Team
              paulmasri Paul
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes