Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was implementing a basic hot-reload feature for a project of mine and had a difficulties I solved by adding a few additional methods to QmlEngine wrapper.
First, I should briefly explain how hot reloading works in my case:
./ui/
directroy where all my.qml
's are stored;hot_reload_pre
on my rootApplicationWindow
-- this method clearsPageLoader
'ssource
and sets it to inactive;hot_reload_post
-- this method makesPageLoader
become active and triggers loading of page where user was before hot reload.In this scenario I faced two problems:
The first one was caused by cryptic
QMetaMethod::invoke: Unable to invoke methods with return values in queued connections
QmlEngine message happens when I try to callinvoke_method
on engine from my watcher thread. I've looked here and there and found this answer on SO. So I copiedinvoke_method
, removedQ_RETURN_ARG
from a template and renamed method to ainvoke_method_noreturn
(meaning this version ofinvoke_method
has no return arg).The second problem was -- QmlEngine and PageLoader was written by clever guys who cares about performance and do caching if possible. And in my case I need exactly opposite -- I need to reset Engine's/PageLoader's cache on hot reload. I found no possibilities to do it from qml itself (moving my PageLoader to inactive and then back to active state wont help), but I found a way to do it from C side by calling methods
engine->trimComponentCache()
andengine->clearComponentCache()
. Unfortunately, named methods were absent in wrapper, so I've added them.And with these two changes I was able to do my simple hot-reload.
I believe someone else may find these addition useful, so here's PR.