Load QML files from file system when using new CMake qt_add_qml_module()
-
When using qt_add_qml_module(), all QML files are properly placed in a QRC which is in turn linked to the application. This is perfectly fine for deployment.
However, during development I prefer loading my QML files directly from the file system. This eliminates the need for recompilation if only OML files are changed.
There is a Qt 6.5 blog post regarding qt_add_qml_module which states the following:
If we do want to load from the normal file system during development (to iterate faster on our QML files without having to recompile), we would be out of luck as we have now hard-coded the qrc path. With Qt 6.5 we have a new option which avoids all the issues.Source: https://www.qt.io/blog/whats-new-for-qml-modules-in-6.5
Now my question is: HOW do we do this? WHAT is the new option in Qt 6.5 that enables us to do this?
-
When using qt_add_qml_module(), all QML files are properly placed in a QRC which is in turn linked to the application. This is perfectly fine for deployment.
However, during development I prefer loading my QML files directly from the file system. This eliminates the need for recompilation if only OML files are changed.
There is a Qt 6.5 blog post regarding qt_add_qml_module which states the following:
If we do want to load from the normal file system during development (to iterate faster on our QML files without having to recompile), we would be out of luck as we have now hard-coded the qrc path. With Qt 6.5 we have a new option which avoids all the issues.Source: https://www.qt.io/blog/whats-new-for-qml-modules-in-6.5
Now my question is: HOW do we do this? WHAT is the new option in Qt 6.5 that enables us to do this?
@Kai-Nickel , did you ever figure this out? I am facing the same issue
-
@Kai-Nickel , did you ever figure this out? I am facing the same issue
@d_h_mcinnes Sorry, I still have no clue
-
@d_h_mcinnes Sorry, I still have no clue
See section "Loading Components: The state so far" which should describe what you are looking for.
-
See section "Loading Components: The state so far" which should describe what you are looking for.
@Christian-Ehrlicher Thank you for pointing out this section.
If I get you right, you propose to use the old variant with an explicit file path:
engine.load("/path/to/Module/Main.qml");
instead of the new method, which loads from qrc implicitly:
engine.loadModule("Module", "Main");
I think I get why this works for Main.qml (and maybe indirectly for all other Files in "Module", too?).
But my application is comprised of multiple modules, each including qml files. How does the loading of "Main.qml" in the engine affect the way the qml files from my other modules are loaded?
-
@Christian-Ehrlicher Thank you for pointing out this section.
If I get you right, you propose to use the old variant with an explicit file path:
engine.load("/path/to/Module/Main.qml");
instead of the new method, which loads from qrc implicitly:
engine.loadModule("Module", "Main");
I think I get why this works for Main.qml (and maybe indirectly for all other Files in "Module", too?).
But my application is comprised of multiple modules, each including qml files. How does the loading of "Main.qml" in the engine affect the way the qml files from my other modules are loaded?
@Kai-Nickel , I found a way to do this, the details are in https://bugreports.qt.io/browse/QTBUG-120435
-
@Kai-Nickel , I found a way to do this, the details are in https://bugreports.qt.io/browse/QTBUG-120435
@d_h_mcinnes Thank you for the link, I finally got the time to try it myself.
Setting the qml source directory as "prefer" in qmldir did the trick for me, too!
To make this more feasible, I ended up setting NO_GENERATE_QMLDIR in qt_add_qml_module(), and providing my own patched qmldir in the RESOURCES list.