[Interest] 5.5/5.6 QMLEngine management

md at rpzdesign.com md at rpzdesign.com
Mon Jan 11 15:00:13 CET 2016


On 1/11/2016 12:53 AM, Bo Thorsen wrote:
> Den 10-01-2016 kl. 03:21 skrev mark diener:
>> Hello List:
>>
>> I have a couple of core QMLEngine questions:
>>
>> Basic Code Snippet:
>>
>> QQmlEngine geng ;
>>
>> QQmlComponent gcomp(&geng)
>> gcomp.setData( ByteArrayofQML , QUrl() ) ;
>> gcomp.create() -> Show the QML in the QML Engine
>> if (gcomp.isError() == false) -> we have visible QML!
>>
>> 1) How does one cause all properties in the root context for QML
>> engine be triggered to re-evaluate their bindings again. For example
>> Text { text: gvariable }, it want text object to re-fetch its own
>> values instead of pushing values with Qobject->setProperty().  Generic
>> pull instead of specific push.
>>
>> Can I cause a disturbance in the QmlContext and that would trigger and
>> "expensive" refetching of text values for example.
>
> On one hand, this question doesn't make sense. QML vars are considered 
> changed immediately, and that's a basic design choice.
>
> OTOH, it's very simple to do this yourself. Just create a function 
> that pulls in the new variable values. You might need a proxy object 
> between the real value place and the QML land, but other than that you 
> need no tricks for it.
>
>> 2) How does one clear out everything loaded in the root QmlEngine 
>> context?
>>
>> What is the best way to clear the root context of qmlengine of
>> everything prior to calling
>> gcomp->setData() and  gcomp->create( ) to load brand new QML into the 
>> QmlEngine?
>>
>> geng->clearComponentCache() ?  Does this really flush everything out
>> regardless of anything that is currently visible on-screen?
>>
>> I do not want to build up a pile of QObjects in the engine, I want
>> them cleanly flushed out.
>
> Again, there are ways you could do this. Store the set of accepted 
> vars and values and reset to exactly those when you want, for example.
>
> But this idea smells badly of a fundamentally bad design. If you need 
> to get rid of variables, reset them, etc. then they probably shouldn't 
> be stored as context on the root engine. This sounds like one of the 
> "how do I do B" because you are doing "A" already questions, and the 
> problem is that "A" is wrong. We get those on this list all the time.
>
> One idea I have used often is to have a backend object that is almost 
> the only object exposed to QML. Inside this one you can set variables 
> on the fly as you want. With the very limited amount of info you have 
> given here this seems like a much more appropriate direction for you.
>
> Bo Thorsen,
> Director, Viking Software.
>
Bo:

Sorry if my information was limited.

What I was trying to say was that for the QMLEngine when it loads and 
displays QML ( component setData()/create() ), I want to trigger in a 
generic way an update to that information.

For example, when I change language from English to Spanish, I want the 
QMLEngine to re-fetch all of its bound values in a generic way, not 
specific hard coded setProperty( objectName,"text") calls to trigger.  
That is a maintenance and code pattern nightmare.  We need some generic 
way from C++ to trigger QML value re-fetch as if the

With respect to QmlEngine->clearComponentCache(), your appreciated 
answer is tied to variables and that is not what I was asking.  When I 
change screens, I want to dump the loaded QML and replace with new QML.  
The documentation does not give me a firm grasp of the relationship to 
C++ QQmlContext, QQmlEngine, and QQmlComponent.setData()/Create().

Now the 2 questions are related in that I could either "Update" the 
currently displayed QML when I change languages.  Or I can Dump the QML 
and reload it with the new language values.

Yes, I know Qt Translation exists, but that is not the point of the 
inquiry here, since I used a different design for my international support.

Cheers,

md



More information about the Interest mailing list