[Qt-qml] Temporary QML Objects
Colin Kern
colin.kern at gmail.com
Thu May 27 02:01:38 CEST 2010
Hi all,
I want to dynamically create QML objects in my application to serve as
visual effects. They're pretty basic QML components that I just want
to appear, animate, and then be destroyed. I'm not sure about the
best way to do this. My program is hybrid C++/QML, so I have a
QDeclarativeView which is the root context and engine for all the QML
of my program. I create the view and then use setSource to set the
QML that makes up my main UI. Now later as the program is running, I
want to start dynamically creating some objects. This is what I tried
just as a proof of concept:
Effect.qml:
import Qt 4.6
Rectangle {
id: rect
width: 100
height: 20
color: "red"
x: 200
NumberAnimation on y { from: 300; to: 100; duration: 1000 }
Component.onCompleted: rect.destroy(1000)
}
and then in a slot in my C++:
QDeclarativeComponent component(view->engine(), QUrl("Effect.qml"));
QObject *myObject = component.create();
this probably isn't the right way to go about this, but I'm not sure
what is. When I run this code, I don't see the Effect elements, but I
do get debug messages saying "Effect.qml:10: Error: Invalid attempt
to destroy() an indestructible object".
Thanks for your help,
Colin
More information about the Qt-qml
mailing list