[Qt-qml] Dynamically created items and properties

Jan Ekholm jan.ekholm at smultron.net
Sun Aug 22 19:28:33 CEST 2010


On Aug 20, 2010, at 9:42 AM, <bea.lam at nokia.com> <bea.lam at nokia.com> wrote:

...

> Usually the bindings are not set until the property is set to a proper value. I'm not sure why this is not happening in your case - perhaps the errors are occurring when the unit is destroyed.
> 
> If this is the case you could use states to ensure the bindings are only set when the unit has a proper value, e.g.
> 
> Image {
> 	id: img
> 	property variant unit
> 
> 	// don't set x, y, source here
> 
> 	Text { id: label }
> 
> 	states: State {
> 		name: "hasUnit"; when: unit != undefined
> 		PropertyChanges { target: img; x: unit.x * 48 + ( unit.y % 2 ) * 24; y: unit.y * 36; source: unit.icon }
> 	}
> }


The above works beautifully and I've used it now for days without any issues. However, I also found
myself needing to bind a Connections to the said magical "unit". It also gives warnings if done in this 
trivial way (which should work):

Connections {
    target: unit
    onSomethingChanged: doFoo()
}

Here "unit" is also undefined when the Connection is parsed and we get the same issue. So, something
that could would is to create a "half" connection like:

Connections {
    id: connectio
    target: null
    onSomethingChanged: doFoo()
}

and later in a PropertyChanges as above set the target to the now valid "unit". This does not really work, as
the PropertyChanges would look like:

PropertyChanges {
    target: connection
    target: unit
}

Slight problem there:

foo.qml: Property value set multiple times

 Is there any way to make that actually work? Some magic escaping or similar? These hacks should
not really be needed at all, but as long as they are, more workarounds are needed.

I'm sorry for being such a pain in the rectal regions, but I've invested so much time in this project now
for it to stumble and collapse at the final stages of development.

-- 
Jan Ekholm
jan.ekholm at smultron.net








More information about the Qt-qml mailing list