[Qt-qml] Dynamically created items and properties

aaron.kennedy at Nokia.com aaron.kennedy at Nokia.com
Wed Jul 28 03:23:45 CEST 2010


Hi,

On 27/07/10 7:19 PM, "ext Jan Ekholm" <jan.ekholm at smultron.net> wrote:

> 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.

To avoid displaying errors for transient states, QML buffers errors until
all bindings have been evaluated and settled into a steady state.  If at
this point "unit" is still unset, it will print the error.

Cheers,

Aaron





More information about the Qt-qml mailing list