[Qt-qml] Change property of dynamically created component
shiping.ji at nokia.com
shiping.ji at nokia.com
Thu Nov 11 08:38:06 CET 2010
Hi,
This explains the case, now we fully understood what was wrong in our approach.
Thanks a lot for Michael and Warwick's help.
BR,
Shiping
-----Original Message-----
From: Brasser Michael (Nokia-MS-Qt/Brisbane)
Sent: 11 November, 2010 03:43
To: Ji Shiping (Nokia-MS/Espoo)
Cc: qt-qml at trolltech.com
Subject: Re: [Qt-qml] Change property of dynamically created component
Hi Shiping,
id's are scoped to the component in which they are defined (and are accessible to subcomponents, but not to containing components) -- perhaps this is the problem you are running into? For example:
// YellowRect.qml
Rectangle {
id: yellowRect
width: 100
height: 100
color: "yellow"
}
//invalid.qml
Rectangle {
YellowRect {}
Rectangle {
color: yellowRect.color // ### this is invalid, as the id "yellowRect" is not accessible in this context
}
}
//valid.qml
Rectangle {
YellowRect { id: myRect }
Rectangle {
color: myRect.color // ### this is valid, as the id "myRect" is accessible in this context
}
}
Likewise, if YellowRect was dynamically created and placed into component X, the "yellowRect" id would not be visible in the context of X.
Regards,
Michael
On 10/11/2010, at 7:39 PM, ext shiping.ji at nokia.com wrote:
> Hi,
>
> That solves the problem. One more related question, does it mean that dynamically created QML objects (incl. e.g. the one created using QDeclarativeComponent::create()) will not have their id registered?
>
> We've noticed the issue that once we load and attach such objects programmatically, future binding update to these newly created objects will not work as it complains the object with the given id is not found. This has nothing to do with the loader though. Please confirm and we will send some sample code if you believe it should work and there is something wrong in our side.
>
> Thanks again.
>
> BR,
> Shiping
>
> -----Original Message-----
> From: Allison Warwick (Nokia-MS-Qt/Brisbane)
> Sent: 10 November, 2010 02:55
> To: Ji Shiping (Nokia-MS/Espoo); Jones Martin (Nokia-MS-Qt/Brisbane); qt-qml at trolltech.com
> Subject: RE: Change property of dynamically created component
>
> The id of a component does not become a new global identifier. i.e. "yellowRect" below:
>
> Component {
> id: yellowRectComponent
> Rectangle {
> id: yellowRect
> width: 100
> height: 100
> color: "yellow"
> }
> }
>
> As you can imagine: if you had 2 loaders that loaded this, what would happen?
>
> So, to fix your example, instead of:
>
> PropertyChanges {
> target: yellowRect
> color: "gray"
> }
>
> You need:
>
> PropertyChanges {
> target: loader.item
> color: "gray"
> }
>
> --
> Warwick
>
> _______________________________________________
> 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