[Interest] QML/C++ tidbit

md at rpzdesign.com md at rpzdesign.com
Fri Oct 9 18:57:15 CEST 2015


Hello List:

For those who are using Loader in QML but triggering that loader from 
C++, I came across a usage pattern technique that may have utility for some.

During the execution of the C++,  loading "componentSource" is NOT a 
synchronous operation if your loader is set to Async == true

In the Loader::onLoaded() function, call an INVOKABLE back into C++ to 
inform C++ that the loader is finished by setting some visible C++ flag

Then inside your C++, execute QGuiApplication::processEvents() 
immediately after setting "componentSource" and wait for the flag to be 
set and then you may proceed to interact with the freshly loaded QML 
objects inside C++ knowing the loader has finished its job.

This allows what is largely an asynchronous process to be made more 
"synchronous" inside your C++, thus allowing you to continue in C++ with 
your GUI logic close to where you loaded the QML to begin with.

I use a timeout to guard against QML errors should my loader stumble 
into poorly formed QML.

You can always try to handle the QMLEngine::warnings() signal, but that
is a work in progress.

I never set my Loader to be synchronous so that I never block the Gui 
Thread with QML loading operations.

Hope the idea resonates with someone in the list.

Cheers,

md

-- 
No spell checkers were harmed during the creation of this message.



More information about the Interest mailing list