Reputation: 109
I have seen many outdated answers about this question, but they do not take the new CMake QML Modules API into consideration.
In short, you declare a qml module in CMake with some QML and/or C++ or asset files and you get a generated plugin to be linked against by your application and a generated qmldir file in the build directory. All files are added to the resource system. I already tried a shortcut to reload the qml in the engine using QQmlApplication::loadFromModule("Main", "Main")
(see link, this is new in 6.5 and does not seem to rely on qrc only).
Is there any chance to hot reload QML files within a running application with the given setup?
Upvotes: 2
Views: 666
Reputation: 649
To make this work, you need to do the following changes:
QQmlApplication::loadFromModule
usage, create a Main
directory and put a Main.qml
file into it.Main/qmldir
file with the contents likemodule Main
Main 1.0 Main.qml
You can also copy the qmldir
file from the build directory, where the files generated by qt_add_qml_module
are located.
QQmlEngine::addImportPath("/path/to/parent/dir/of/Main")
, before calling QQmlApplication::loadFromModule("Main", "Main")
.As long as you add your module to the import path (even if it's conditionally decided at runtime), the loadFromModule
function will prefer to load Main.qml
from the disk, and not via .qrc
.
Upvotes: 0