Closed IriaSomobu closed 9 months ago
It is more than I intended indeed -- I just wanted invoke
to work one way or another, and with this PR it works.
I guess it is possible for me tinker with invoke_method
and connections a bit later, when there will be more free time.
As for tests -- do you have any ideas on what exactly should we test on these functions?
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.