Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. qt_add_qml_module with absolute QML file paths causes qmlcachegen error
Forum Updated to NodeBB v4.3 + New Features

qt_add_qml_module with absolute QML file paths causes qmlcachegen error

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 135 Views 1 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.
  • L Offline
    L Offline
    lkimuka
    wrote last edited by lkimuka
    #1

    Correct situation (works fine):

    Project structure (irrelevant files omitted):

    D:/libraries/WrapUp/
     └─ src/
         ├─ CMakeLists.txt
         └─ qml/
             └─ WrapUpAbout.qml
    

    With the following CMake code everything works as expected:

    qt_add_executable(WrapUp ${SOURCE_FILES})
    
    qt_add_qml_module(WrapUp
        URI "com.cppmore.wrapup"
        VERSION 1.0
        QML_FILES
            “qml/WrapUpAbout.qml”
    )
    qt_add_translations(WrapUp TS_FILES ${TS_FILES} LUPDATE_OPTIONS -no-obsolete)
    

    Problematic situation:

    My actual project looks like this:

    D:/libraries/WrapUp/
     ├─ resources/
     │   └─ qml/
     │       └─ WrapUpAbout.qml
     └─ src/
         └─ CMakeLists.txt
    

    Since qml/ and CMakeLists.txt are not in the same directory, I cannot directly specify a relative path for qt_add_qml_module. I tried the following:

    set_source_files_properties(
        "D:/libraries/WrapUp/resources/qml/WrapUpAbout.qml" 
        PROPERTIES 
        QT_RESOURCE_ALIAS "WrapUpAbout.qml"
    )
    
    qt_add_qml_module(WrapUp
        URI "com.cppmore.wrapup"
        VERSION 1.0
        QML_FILES
            "D:/libraries/WrapUp/resources/qml/WrapUpAbout.qml"
    )
    

    But I get this error:

    > cmake --build ./build
    CMake is re-running because D:/libraries/WrapUp/build/src/CMakeFiles/generate.stamp is out-of-date.
      the file 'D:/libraries/WrapUp/src/CMakeLists.txt'
      is newer than 'D:/libraries/WrapUp/build/src/CMakeFiles/generate.stamp.depend'
      result='-1'
    -- Selecting Windows SDK version 10.0.26100.0 to target Windows 10.0.19045.
    -- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
    -- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
    -- QML_FILES: D:/libraries/WrapUp/resources/qml/WrapUpAbout.qml;D:/libraries/WrapUp/resources/qml/WrapUpMenuBar.qml;D:/libraries/WrapUp/resources/qml/main.qml
    -- QML_FILE_NAMES: WrapUpAbout.qml;WrapUpMenuBar.qml;main.qml
    -- Configuring done (0.8s)
    -- Generating done (0.3s)
    -- Build files have been written to: D:/libraries/WrapUp/build
    
      1>Checking Build System
      Building Custom Rule D:/libraries/WrapUp/CMakeLists.txt
      Building Custom Rule D:/libraries/WrapUp/CMakeLists.txt
      1>Automatic MOC for target WrapUp
      Running AUTOMOC file extraction for target WrapUp
      Running moc --collect-json for target WrapUp
      Automatic QML type registration for target WrapUp
      Running rcc for resource qmake_com_cppmore_wrapup
      Generating .rcc/qmlcache/WrapUp_qmlcache_loader.cpp
      Running rcc for resource WrapUp_raw_qml_0
      Building Custom Rule D:/libraries/WrapUp/src/CMakeLists.txt
      Generating .rcc/qmlcache/WrapUp_/resources/qml/WrapUpAbout_qml.cpp, .rcc/qmlcache/WrapUp_/resources/qml/WrapUpAbout_qml.cpp.aotstats
      Error creating directory "D:/libraries/WrapUp/build/src/.rcc/qmlcache/WrapUp_../resources/qml".
    D:\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(254,5): error MSB8066: “D:\libraries\WrapUp\build\CMakeFiles\9e5228bf0ebbc21310f7a5dbc5cf0aea\qt6wrapup_metatypes.json.gen.rule 
    ;D:\libraries\WrapUp\build\CMakeFiles\39b2acbd3902d61e86576894dd8662e6\wrapup_qmltyperegistrations.cpp.rule;D:\libraries\WrapUp\build\CMakeFiles\c3590fc0bbf25252fc327eba035db7b1\qrc_qmake_com_cppmore_wrapup.cpp.rule;D:\libra 
    ries\WrapUp\build\CMakeFiles\9b2df191bdcd22186ae42596e6c41ac2\WrapUp_qmlcache_loader.cpp.rule;D:\libraries\WrapUp\build\CMakeFiles\be821e174df26c8b141b726b6bc6d578\WrapUpAbout_qml.cpp.rule;D:\libraries\WrapUp\build\CMakeFile 
    s\c3590fc0bbf25252fc327eba035db7b1\qrc_WrapUp_raw_qml_0.cpp.rule;D:\libraries\WrapUp\src\CMakeLists.txt”
    

    Question:
    I know the issue is related to the path, but how should I fix it? (I don't want to change the project structure)

    JKSHJ 1 Reply Last reply
    0
    • L lkimuka

      Correct situation (works fine):

      Project structure (irrelevant files omitted):

      D:/libraries/WrapUp/
       └─ src/
           ├─ CMakeLists.txt
           └─ qml/
               └─ WrapUpAbout.qml
      

      With the following CMake code everything works as expected:

      qt_add_executable(WrapUp ${SOURCE_FILES})
      
      qt_add_qml_module(WrapUp
          URI "com.cppmore.wrapup"
          VERSION 1.0
          QML_FILES
              “qml/WrapUpAbout.qml”
      )
      qt_add_translations(WrapUp TS_FILES ${TS_FILES} LUPDATE_OPTIONS -no-obsolete)
      

      Problematic situation:

      My actual project looks like this:

      D:/libraries/WrapUp/
       ├─ resources/
       │   └─ qml/
       │       └─ WrapUpAbout.qml
       └─ src/
           └─ CMakeLists.txt
      

      Since qml/ and CMakeLists.txt are not in the same directory, I cannot directly specify a relative path for qt_add_qml_module. I tried the following:

      set_source_files_properties(
          "D:/libraries/WrapUp/resources/qml/WrapUpAbout.qml" 
          PROPERTIES 
          QT_RESOURCE_ALIAS "WrapUpAbout.qml"
      )
      
      qt_add_qml_module(WrapUp
          URI "com.cppmore.wrapup"
          VERSION 1.0
          QML_FILES
              "D:/libraries/WrapUp/resources/qml/WrapUpAbout.qml"
      )
      

      But I get this error:

      > cmake --build ./build
      CMake is re-running because D:/libraries/WrapUp/build/src/CMakeFiles/generate.stamp is out-of-date.
        the file 'D:/libraries/WrapUp/src/CMakeLists.txt'
        is newer than 'D:/libraries/WrapUp/build/src/CMakeFiles/generate.stamp.depend'
        result='-1'
      -- Selecting Windows SDK version 10.0.26100.0 to target Windows 10.0.19045.
      -- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
      -- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR) 
      -- QML_FILES: D:/libraries/WrapUp/resources/qml/WrapUpAbout.qml;D:/libraries/WrapUp/resources/qml/WrapUpMenuBar.qml;D:/libraries/WrapUp/resources/qml/main.qml
      -- QML_FILE_NAMES: WrapUpAbout.qml;WrapUpMenuBar.qml;main.qml
      -- Configuring done (0.8s)
      -- Generating done (0.3s)
      -- Build files have been written to: D:/libraries/WrapUp/build
      
        1>Checking Build System
        Building Custom Rule D:/libraries/WrapUp/CMakeLists.txt
        Building Custom Rule D:/libraries/WrapUp/CMakeLists.txt
        1>Automatic MOC for target WrapUp
        Running AUTOMOC file extraction for target WrapUp
        Running moc --collect-json for target WrapUp
        Automatic QML type registration for target WrapUp
        Running rcc for resource qmake_com_cppmore_wrapup
        Generating .rcc/qmlcache/WrapUp_qmlcache_loader.cpp
        Running rcc for resource WrapUp_raw_qml_0
        Building Custom Rule D:/libraries/WrapUp/src/CMakeLists.txt
        Generating .rcc/qmlcache/WrapUp_/resources/qml/WrapUpAbout_qml.cpp, .rcc/qmlcache/WrapUp_/resources/qml/WrapUpAbout_qml.cpp.aotstats
        Error creating directory "D:/libraries/WrapUp/build/src/.rcc/qmlcache/WrapUp_../resources/qml".
      D:\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(254,5): error MSB8066: “D:\libraries\WrapUp\build\CMakeFiles\9e5228bf0ebbc21310f7a5dbc5cf0aea\qt6wrapup_metatypes.json.gen.rule 
      ;D:\libraries\WrapUp\build\CMakeFiles\39b2acbd3902d61e86576894dd8662e6\wrapup_qmltyperegistrations.cpp.rule;D:\libraries\WrapUp\build\CMakeFiles\c3590fc0bbf25252fc327eba035db7b1\qrc_qmake_com_cppmore_wrapup.cpp.rule;D:\libra 
      ries\WrapUp\build\CMakeFiles\9b2df191bdcd22186ae42596e6c41ac2\WrapUp_qmlcache_loader.cpp.rule;D:\libraries\WrapUp\build\CMakeFiles\be821e174df26c8b141b726b6bc6d578\WrapUpAbout_qml.cpp.rule;D:\libraries\WrapUp\build\CMakeFile 
      s\c3590fc0bbf25252fc327eba035db7b1\qrc_WrapUp_raw_qml_0.cpp.rule;D:\libraries\WrapUp\src\CMakeLists.txt”
      

      Question:
      I know the issue is related to the path, but how should I fix it? (I don't want to change the project structure)

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote last edited by
      #2

      @lkimuka said in qt_add_qml_module with absolute QML file paths causes qmlcachegen error:

      how should I fix it?

      The expectation is to have a CMakeLists.txt file in the same folder as your *.qml files. You can then link that folder to the rest of your project using add_subdirectory().

      Note: *.qml files are considered source code, not resources.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      L 1 Reply Last reply
      0
      • JKSHJ JKSH

        @lkimuka said in qt_add_qml_module with absolute QML file paths causes qmlcachegen error:

        how should I fix it?

        The expectation is to have a CMakeLists.txt file in the same folder as your *.qml files. You can then link that folder to the rest of your project using add_subdirectory().

        Note: *.qml files are considered source code, not resources.

        L Offline
        L Offline
        lkimuka
        wrote last edited by
        #3

        @JKSH said in qt_add_qml_module with absolute QML file paths causes qmlcachegen error:

        The expectation is to have a CMakeLists.txt file in the same folder as your *.qml files. You can then link that folder to the rest of your project using add_subdirectory().

        Thank you. This approach is correct. Placing the *.qml files in the src directory is indeed more appropriate. I just wanted to see how to write the CMake configuration when separating QML and C++ code.

        1 Reply Last reply
        0

        • Login

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