[Qt-qml] Accessing elements created with js
michael.brasser at nokia.com
michael.brasser at nokia.com
Mon Jul 12 07:10:36 CEST 2010
Hi Anton,
On 09/07/2010, at 6:09 PM, ext Anton Alferov wrote:
> Is there any way to access element by it's id if that element was created using js?
The set of ids in a component is effectively fixed at startup -- this allows us to do some important optimizations for binding resolution.
> For example, in the attached sample element rect1 created with js, and the rect2 one tries to use it by id but unsuccessfully - the rect1 treats as undefined object.
For an example like the above Loader should work very well; I'm not sure how close that matches your actual use case though. Have you tried using Loader?
Since createQmlObject returns the object it has created, you could possibly also look at saving the return value in an accessible property (though in the case of bindings that would likely generate a lot of warnings until the object was actually created)
Item {
property variant rect1
...
function create() {
rect1 = Qt.createQmlObject(...)
}
}
Regards,
Michael
More information about the Qt-qml
mailing list