[Qt-qml] Dynamically created items and properties

Jason H scorp1us at yahoo.com
Tue Jul 27 15:00:41 CEST 2010


I am very much in your position. There's not enough documentation on the 
internal 'magic' of QML, which is my mental block as well.

I was told time time ago that y: parent.height/3 would be cintonually evaluated. 
At which point I realized I didn't know enough. I've searched the docs and I 
don't think anything has been added yet.

A page on QML evaluation internals would really help us I think.





----- Original Message ----
From: Jan Ekholm <jan.ekholm at smultron.net>
To: qt-qml at trolltech.com
Sent: Tue, July 27, 2010 5:19:46 AM
Subject: Re: [Qt-qml] Dynamically created items and properties

On Tuesday 27 July 2010 01:42:36 Martin Jones wrote:
> The above is not a binding.  It is an assignment.  Bindings are created
> using the colon syntax.

Ah, great! I hoped there was something that I just didn't grok. I've never 
noticed the difference before.

> One solution is to provide the Unit to the QML item and let it setup the
> bindings:
> 
> Unit.qml:
> 
> Image {
>     property variant unit
>     x: unit.x * 48 + ( unit.y % 2 ) * 24
>     y: unit.y*36
>     source: unit.icon
>     unit_id: unit.id
> }
> 
> Then you just need to assign the unit to the QML item and it will take care
> of its bindings.

Looks elegant and works perfectly! Thank you Martin!

However, I don't understand why this works at all without warnings or errors. 
Initially when the Image is created the "unit" is undefined and the initial 
property binding is using that undefined unit. Or is there some magic that 
checks for the undefinedness and avoids errors? And then when the property is 
actually set to a valid object all other "bound properties" are also set? In 
other cases when something has been undefined there has been lots of warnings 
about using [undefined] properties.

Us old farts have a hard time with magic. :)

-- 
By reading this message, you may be causing Armageddon. Needless to say,
Armageddon will wipe out your hard drive and damage your computer.
                                -- Email hoax as seen on Hoaxbusters.com
                
_______________________________________________
Qt-qml mailing list
Qt-qml at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-qml



      



More information about the Qt-qml mailing list