aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript/data/signalEmitted.3.qml
diff options
context:
space:
mode:
authorChris Adams <christopher.adams@nokia.com>2012-05-01 12:11:45 +1000
committerQt by Nokia <qt-info@nokia.com>2012-05-09 00:56:16 +0200
commit029e510256a1a6ea8f30db75fa0745cad01353cb (patch)
treeafee148629983a2490b8ab176dcb050dfc27bd29 /tests/auto/qml/qqmlecmascript/data/signalEmitted.3.qml
parent68b899266ca209d43026376a6cf9d7bbdc3483b8 (diff)
Fix edge case in signal emission semantics
Signal emission triggered by property changes during an onDestruction handler was previously not well tested. This commit adds several unit tests to ensure correct behaviour in that situation. Those unit tests showed a problem in signal emission related to when children objects are cleaned up. This commit also ensures that if such children own their own context, their onDestruction handlers are called prior to marking the child as deleted. Change-Id: Ibf84ae56ba1134e5d6402b742aee1bdc0e5e4e15 Reviewed-by: Matthew Vogt <matthew.vogt@nokia.com>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript/data/signalEmitted.3.qml')
-rw-r--r--tests/auto/qml/qqmlecmascript/data/signalEmitted.3.qml34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/signalEmitted.3.qml b/tests/auto/qml/qqmlecmascript/data/signalEmitted.3.qml
new file mode 100644
index 0000000000..0cae5c02d8
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/signalEmitted.3.qml
@@ -0,0 +1,34 @@
+import QtQuick 2.0
+import Qt.test 1.0 as ModApi
+
+Item {
+ id: root
+
+ property bool success: false
+ property bool c1HasBeenDestroyed: false
+
+ property Item c1 // not a js reference, so won't keep it alive
+
+ SignalEmittedComponent {
+ id: c2
+ property int c1a: if (root.c1) root.c1.a; else 0; // will change during onDestruction handler of c1.
+ function c1aChangedHandler() {
+ // this should still be called, after c1 has been destroyed by gc,
+ // because the onDestruction handler of c1 will be triggered prior
+ // to when c1 will be invalidated.
+ if (root.c1HasBeenDestroyed && c1a == 20) root.c1.setSuccessPropertyOf(root, true);
+ }
+ }
+
+ Component.onCompleted: {
+ // dynamically construct sibling. When it goes out of scope, it should be gc'd.
+ // note that the gc() will call weakqobjectcallback which will set queued for
+ // deletion flag -- thus QQmlData::wasDeleted() will return true for that object..
+ var c = Qt.createComponent("SignalEmittedComponent.qml", root);
+ var o = c.createObject(null); // JS ownership
+ o.onAChanged.connect(c2.c1aChangedHandler);
+ c1 = o;
+ c1HasBeenDestroyed = true;
+ // return to event loop.
+ }
+}