[Qt-qml] Set custom property in onChildrenChanged?

michael.brasser at nokia.com michael.brasser at nokia.com
Thu Oct 28 07:03:15 CEST 2010


Hi,

On 26/10/2010, at 10:49 PM, ext Charley Bay wrote:

> Curious problem, this should work, right?
> 
> //FILE: MyRect.qml
> Rectangle {
>  property double myDouble: 0
> }
> 
> //FILE: MyParent.qml
> Item {
>  id: myParent
>  onChildrenChanged: {
>    for(var i = 0; i < myParent.children.length; ++i) {
>      // Error:  Cannot assign to non-existent property "myDouble"
>      myParent.children.[i].myDouble = 1.0
>    }
>  }
> }
> 
> MyRect {
>  parent: myParent
> }
> 
> Everything instantiates properly, and "MyRect" is properly
> being parented under "MyParent", with "onChildrenChanged"
> being called.
> 
> Can I not access the custom property?  Do I need to cast
> to a "MyRect" inside "onChildrenChanged"?
> 
> In this case, I *always* know it is a "MyRect", but I thought
> the dynamic typing would have found the "myDouble"
> property.
> 
> Should this code work?  (Or what should I do instead?)

Yes, it should work (with the syntax fix already mentioned). Trying it with HEAD everything seems to work correctly (myDouble is set to 1; no errors), so perhaps its a bug in 4.7.0 that's been fixed since?

Regards,
Michael



More information about the Qt-qml mailing list