[SOLVED] Create qml object in C++ setting a parent
I've created a component like this (VisualObj.qml):
Now I need to create that object in C++ ...below my code:
QDeclarativeComponent component(this->rootContext->engine(), QUrl("qrc:/qml/VisualObj.qml"));
object = component.create();
I call this code (as slot) in Component.onCompleted of a Page component...my problem is that the object I've created is not displayed
in the Page!
Ok, that is because I've not set the parent...I've just tried to get it as parameter of the slot (yes...I'm crazy) and it works: the parameter is a valid qml object and so I use that:
but nothing, even I've set the "visible" property of the new dynamic object!
How can I resolve that? Is there a correct way to achieve what I want?
thanks to all
P.S. due to the big flexibility of QML and C++, and relatively new technology, I think that at least an official book is needed!
Are you sure the ctor is called ?
if the object has no height, it is likely that it will not be visible, so did you
put @object->setProperty("height", 90);@ as well?
thank you for resposes...I've resolved it:
1 - as dmcr said, object must be resized
2 - the technique to pass qml object thru c++ slot function is valid and it works
3 - when I create object in C++ is a good manner to convert it in QDeclarativeItem and not use QObject directly; so I've set parent with setParentItem() that seems to work very well then setParent()
4 - I set parent relation (point 3) at the end of all other assignments (width, height and so on) otherwise the component isn't shown
That's all :)
Thank you for support
Prepend the title of thread with [SOLVED], thanks.
Sorry...i forgot it!