GIPdA / runtimeqml

Adds non-intrusive runtime QML reload capabilities to your Qt project.
BSD 3-Clause "New" or "Revised" License
17 stars 3 forks source link

[Question] Does this program kill the main window everytime that reload() function called? #2

Open LinArcX opened 5 years ago

LinArcX commented 5 years ago

I see that every little change will cause the app to restart. is it right? I also follow another idea to hot-reload qml files: https://qml.guide/live-reloading-hot-reloading-qml/ He uses Loader component and clearComponentCache() function in c++ side to re-evalute qml files. But i can't successfully run his sample app to see the actual behavior. Imagine our app is very big and every time restart whole app isn't very efficient. so the ability to re-load some parts of a qml page would be very awesome. Is there any way to do it via runtimeqml?

GIPdA commented 5 years ago

It is not the whole app per say that is reloaded, but the whole QML part of it. All windows are closed and deleted and the main QML file is reloaded. All C++ stuff is not touched. Of course it depends on what you do in your QML, you should put all logic & states into C++ for it to work properly. Reloading the full QML every time is pretty fast even with large codebases. AFAIK there is no possibility to reload only some QML files.

You can of course use a Loader for that, but it adds an extra layer and Loaders are sometimes finicky to use (properties, bindings and stuff). And that extra layer stays here even in release builds. RuntimeQML can be completely removed very easily with a simple #ifdef.

I looked at the link you posted, interesting stuff. I'm not sure what effects calling QQmlEngine::clearComponentCache() would have on other still loaded components though, but I guess nothing bad? Testing is required :P Note that the loader only reloads itself, other loaders using the same QML file would also need to be reloaded. And mixing with the QRC would also require extra work getting the paths right. RuntimeQML is transparent with that, no need to adapt anything for it to work (unless when using a file selector).

Personally I don't want to get any dev-only related stuff to creep in the QML because you can't easily get rid of it. And as I said, reloading everything is very fast, so having the ability to reload only a specific part is not very useful, especially if it depends on an extra Loader (a big no-no for me).

If your app can't be reloaded, you're doing it wrong ;)

Hope that helps!

LinArcX commented 5 years ago

Thank you so much for explanations.