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

QML modules' don't work if defined in subdirectory of target (CMake API)



    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.6.1, 6.7.0 Beta3, 6.8
    • Linux (Manjaro)


      this issue occurs with the CMake API for QML modules. I've encountered the error when trying to create a QML module in the subdirectory of the module's target. Here are the steps to reproduce the issue:

      First, I've created a new project with the following directory structure:

       +-- CMakeLists.txt (root)
       +-- main.cpp
       +-- gui
          +-- CMakeLists.txt (child)
          +-- Main.qml

      Inside the root CMakeLists, I've called qt_standard_project_setup and created a new executable (app):
      qt_add_executable(app main.cpp)

      Then I've created a new QML module (example) on target app inside the child CMakeLists:
       URI example
       QML_FILES Main.qml

      When I run CMake, it fails on step Automatic QML type registration for target app with the following output:

      FAILED: app_qmltyperegistrations.cpp qml/example/app.qmltypes build/app_qmltyperegistrations.cpp build/qml/example/app.qmltypes 
      cd build/qml && /usr/lib/qt6/qmltyperegistrar --generate-qmltypes=build/qml/example/app.qmltypes --import-name=example --major-version=254 --minor-version=254 @build/qmltypes/app_foreign_types.txt -o build/app_qmltyperegistrations.cpp build/meta_types/qt6app_debug_metatypes.json && /usr/bin/cmake -E make_directory build/.generated && /usr/bin/cmake -E touch build/.generated/app.qmltypes
      Error 5 while parsing build/meta_types/qt6app_debug_metatypes.json: illegal value
      ninja: build stopped: subcommand failed.

      I've simplified the build directory path to build and bolded the actual error. The qt6app_debug_metatypes.json file is empty (size=0).

      If I instead move the Main.qml file to root directory and move the QML module declaration to root CMakeLists, everything works as intended. Interestingly, if I then go back to the erroneous directory structure, CMake works correctly until I remove the build folder, after which it will again raise the error described above.

      Creating a new target using qt_add_library, making it the QML module target and linking the library to root executable works, but it isn't what I'm aiming for.

      I am using CMake 3.28.1 and Qt 6.6.1 on Linux (Manjaro).


        Issue Links

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



              qtbuildsystem Qt Build System Team
              mbugdol Michał Bugdoł
              0 Vote for this issue
              3 Start watching this issue



                Gerrit Reviews

                  There are no open Gerrit changes