Hi,
This happens because the second BoxThing is created in the context of the
first. When the first BoxThing is destroyed, the second ceases to function.
If we allowed the second to continue executing, what should names like
"boxThing" resolve to?
Cheers,
Aaron
On 19/08/2011, at 3:50 PM, ext Kimble Young wrote:
Hi,
I am trying to create instances of objects using Qt.createQmlObject and then
from the same function destroy the object doing the creation. When I do this
the objects seem to remain but all their javascript functions cease to work. If
the parent is not destroyed everything works as normal. I am specifying a
parent in the call to createQmlObject that is not destroyed so I am confused as
to why the objects cease to function normally.
I've included an example down the bottom, main.qml is the qml to run.
In this example you would expect to be able to able to click the red box, have
it make a new red box and that new red box is then able to be clicked again and
a new one made and old one destroyed and so on. In fact only the first red box
reacts to clicks and the dynamically created one doesn't.
So my question is why does this happen and how could I get around it?
I have a need to be able to create new objects and destroy the old one
dynamically. I also can't use createComponent/createObject as there are other
issues with that approach.
Thanks in advance,
Kimble Young
main.qml
import QtQuick 1.0
Rectangle {
id: mainRectangle
width: 360
height: 360
Component.onCompleted: {
Qt.createQmlObject("import QtQuick 1.0; BoxThing { x:" + Math.random()
* 360 + "; y:" + Math.random() * 360 + "}", mainRectangle );
}
}
BoxThing.qml
import QtQuick 1.0
Rectangle {
id: boxThing
width: 50
height: 50
color: "red"
MouseArea {
anchors.fill: parent
onClicked: {
console.log("I have been clicked");
Qt.createQmlObject("import QtQuick 1.0; BoxThing { x:" +
Math.random() * 360 + "; y:" + Math.random() * 360 + "}", mainRectangle);
boxThing.destroy();
}
}
}
_______________________________________________
Qt-qml mailing list
[email protected]<mailto:[email protected]>
http://lists.qt.nokia.com/mailman/listinfo/qt-qml
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-qml