Ensure that variant property references keep QObjects alive
[profile/ivi/qtdeclarative.git] / tests / auto / qml / qqmlecmascript / data / signalEmitted.4.qml
1 import QtQuick 2.0
2 import Qt.test 1.0 as ModApi
3
4 Item {
5     id: root
6
7     property bool success: false
8     property bool c1HasBeenDestroyed: false
9
10     SignalEmittedComponent {
11         id: c2
12         function c1aChangedHandler() {
13             // this should still be called, after c1 has been destroyed by gc,
14             // because the onDestruction handler of c1 will be triggered prior
15             // to when c1 will be invalidated.
16             if (root.c1HasBeenDestroyed)
17                 root.success = true;
18         }
19     }
20
21     Component.onCompleted: {
22         // dynamically construct sibling.  When it goes out of scope, it should be gc'd.
23         // note that the gc() will call weakqobjectcallback which will set queued for
24         // deletion flag -- thus QQmlData::wasDeleted() will return true for that object..
25         var comp = Qt.createComponent("SignalEmittedComponent.qml", root);
26         var c1 = comp.createObject(null); // JS ownership
27         c1.onAChanged.connect(c2.c1aChangedHandler);
28         c1HasBeenDestroyed = true; // gc will collect c1.
29         // return to event loop.
30     }
31
32     function destroyC2() {
33         // we must gc() c1 first, then destroy c2, then handle events.
34         c2.destroy();
35     }
36 }