[Qt-qml] Dynamically created items and properties

Jan Ekholm jan.ekholm at smultron.net
Tue Jul 27 11:19:46 CEST 2010


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
				



More information about the Qt-qml mailing list