Qt6 how to load qml sources at runtime
-
Hi
How do I make a qt6 cmake-based app load qml sources at runtime? I have an embedded target, and I want to be able to edit qml files on the device instead of recompiling & redeploying.I have example code here: https://github.com/DanielMcInnes/helloQmlTc branch: 'load-qml-at-runtime')
I can't see any options in
qt_add_qml_modulethat do what I want.NO_CACHEGENdoesn't do it.I tried the following, without success. Any edits after building are ignored.
Loader { anchors.bottom: parent.bottom source: "file:///path/to/MyRectangle.qml" } -
Hi
How do I make a qt6 cmake-based app load qml sources at runtime? I have an embedded target, and I want to be able to edit qml files on the device instead of recompiling & redeploying.I have example code here: https://github.com/DanielMcInnes/helloQmlTc branch: 'load-qml-at-runtime')
I can't see any options in
qt_add_qml_modulethat do what I want.NO_CACHEGENdoesn't do it.I tried the following, without success. Any edits after building are ignored.
Loader { anchors.bottom: parent.bottom source: "file:///path/to/MyRectangle.qml" }@d_h_mcinnes
You're doing the right thing. The path toMyRectangle.qmlmust be available at run time. You might wanna at the qml file as a resource, to be sure of that. -
@d_h_mcinnes
You're doing the right thing. The path toMyRectangle.qmlmust be available at run time. You might wanna at the qml file as a resource, to be sure of that.@Axel-Spoerl Thank you. By adding the qml file as a resource, and doing:
Loader { source: "file:///path/to/MyRectangle.qml" // loads qml at runtime // source: "qrc:/MyRectangle.qml" // loads whatever the source was at compile time }... I can get a Loader to load qml at runtime. However, for my use case, I need all of my qml types to load at runtime without using a Loader.
eg. in the following code, I need 'first' to be loaded at runtime.
MyRectangle { id: first } // this is defined at compile time Loader { anchors.bottom: parent.bottom source: "file:///path/to/MyRectangle.qml" // this is defined at run time }I think this might be a bug / lack of documentation, I'll file a bug and see what the developers say.
-
-
@Axel-Spoerl , fyi I got a reply in my bug report that got this working for me. The details are in the ticket, but the magic step is to manually remove the 'prefer' line from MyModule/qmldir in the build directory.