qt_add_qml_module and project structure
-
main.qml located at project_root/qml/main.qml (${CMAKE_CURRENT_SOURCE_DIR}/qml/main.qml)
CMakeLists.txt:
... qt_add_executable(untitled main.cpp ) qt_add_qml_module(untitled URI qml VERSION 1.0 QML_FILES qml/main.qml ) ...
main.cpp:
engine.load(QUrl("qrc:/qml/main.qml"));
Application output:
qrc:/qml/main.qml: No such file or directory
Qt version is 6.4.2/6.4.3. Why main.qml is unaccessible while it should be available at "qrc:/${URI}/main.qml"?
-
@morte hi
you have to declare your "qrc:/" resources into a specific file.
This is described hereand you have to declare this .qrc file into your CmakeLists.txt, not forgetting to set CMAKE_AUTORCC on, which isn't done by default in QtQuick.
set(CMAKE_AUTORCC ON) qt_add_executable(my_app application.qrc main.cpp )
-
@ankou29666 no, in case of Qt 6.2+ with qt_add_qml_module() thats not the right way to add qml files as qt_add_qml_module() registers them in resource system
-
@morte oops yes sorry I didn't pay attention that you used that syntax inside your CMakeLists.txt (I use the qrc files instead thus the confusion).
but what about autorcc ?
1st edit : I am unsure but I would try adding the prefix /
qt_add_qml_module(untitled URI qml VERSION 1.0 PREFIX "/" QML_FILES qml/main.qml )
2nd edit : in fact no, I'm confusing qt_add_qml_module with qt_add_resources, so that might be RESOURCE_PREFIX instead of PREFIX ?
-
-
-
However i still dont understand is there relation between URI and project directory tree. Why they write in documentation "The easiest way to structure QML modules is to keep them in directories named by their URIs." as i can set URI to "my.new.module" while on project tree files can be located at "project_root/whatever/" e.g. whats point to mimic URI in directory tree