Has anyone been able to hot reload all QML files when using a ApplicationWindow
? I found a few examples like https://qml.guide/live-reloading-hot-reloading-qml/ and https://www.slideshare.net/ICSinc/how-best-to-realize-a-runtime-reload-of-qml, but mostly they use Loader
and as ApplicationWindow
needs to be the root item, this does not work (no window appears) to just reload all QML stuff.
I tried:
ApplicationWindow {
id: window
visibility: "FullScreen"
Shortcut {
sequence: "F5"
context: Qt.ApplicationShortcut
onActivated: {
window.close();
app.loadQml();
}
}
...
}
where app
is a context property I set on C++ side and the function does:
void App::loadQml()
{
qml_engine_.clearComponentCache();
// Use "qrc:/Main.qml" for Qt Resource System.
// Use "Main.qml" for file system.
qml_engine_.load(QUrl(QStringLiteral("Main.qml")));
}
This code kind of works once, the window dis- and reapears but the shortcut only works once but no second time...
Any ideas how to implement this?
Shortcut
– bardao