I have a QML-based app that loads a main.qml
file from the file system like this:
myEngine->load("main.qml");
This works fine, but I'd like to "reload" the engine in case the main.qml was replaced with a newer version.
What I tried so far was calling load()
again, assuming that the engine will automatically reset itself like in other Qt classes.
Unfortunately this is not the case. If I call the method again, another window will appear with the contents of the updated qml file, while the original window stays open and continues to display the old qml file.
To fix this I tried to call load(QUrl())
, followed by clearComponentCache()
and a final load call for the new file. This results in the same effect.
Any ideas how I can "properly" reload a QML engine while the application is running?
clearComponentCache()
looks like it's only related to components, and hence doesn't account for instances of those components. – Skilken