[Interest] Disconnecting signals when object destroyed
Николай Шатохин
n.shatokhin at gmail.com
Fri Oct 5 20:17:22 CEST 2012
Hello.
I found that QML trying to call object's methods even when it destroyed.
It's my main.qml file:
import QtQuick 1.1
Rectangle {
id: appWindow
width: 360
height: 360
property int i: 0;
property real step: 0.1;
property Component component;
signal trigger(int dx)
Text {
text: qsTr("Hello World")
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
//Qt.quit();
trigger(100);
component = Qt.createComponent("Note.qml");
if(component != null)
continueCreation();
else
component.ready.connect(continueCreation);
}
}
onTrigger: {
console.log("parent trigger");
}
function destruction(obj)
{
console.log("destruction");
trigger.disconnect(obj.move);
}
function continueCreation()
{
var sprite = component.createObject(appWindow, {"x": 100, "y":
100, "color":Qt.rgba(1, i*step, 1-i*step, 1)});
if (sprite == null) {
// Error Handling
console.log("Error creating object");
}
sprite.destruction.connect(destruction);
trigger.connect(sprite.move);
i++;
}
}
It's my Note.qml file:
import QtQuick 1.1
Rectangle {
id: note
width: 100
height: 62
color: "red"
//signal move();
signal destruction(variant obj);
MouseArea {
anchors.fill: parent
onClicked: {
destruction(this);
note.destroy();
}
}
function move(dx)
{
x += dx
}
}
Why it can't disconnect signal when object destroyed? How to do this right?
Sorry, I'm novice in QML.
Best regards,
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121005/643de20f/attachment.html>
More information about the Interest
mailing list