qt_add_qml_module with absolute QML file paths causes qmlcachegen error
-
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) -
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)@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.
-
@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.
@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.