[Qt-qml] Component and createObject

Alan Alpert alan.alpert at nokia.com
Wed Apr 21 13:08:28 CEST 2010


 Onsdag 21. april 2010 20:41:56 skrev Dominic Genest :
> Hi,
> 
> I think I misunderstand something about dynamic object creation. In my
> code here, "rond.createObject()" doesn't do anything. I guess this
> method is not indended to be used that way. Is there a way to
> dynamically create an object from a component which is specified in a
> "Component{...}" block in the same file?
> 
> Thanks; regards,
> 
> Dom

What you misunderstood was a detail on createObject, that it doesn't set the 
parent of the item. Thus the object is created as desired, but because it is 
not inserted into a place in the scene it will never be drawn.

If give the root item an id, like 'root', then change the script snippet to 
var newObject = rond.createObject(); newObject.parent = root
then it will work as you intended.

-- 
Alan Alpert
Software Engineer
Nokia, Qt Development Frameworks



More information about the Qt-qml mailing list