aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlecmascript/data/signalEmitted.4.qml
blob: 764ed6e6cab8fec4cddc3f82216e602b3e034b4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import QtQuick 2.0
import Qt.test 1.0 as ModApi

Item {
    id: root

    property bool success: false
    property bool c1HasBeenDestroyed: false

    SignalEmittedComponent {
        id: c2
        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)
                root.success = 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 comp = Qt.createComponent("SignalEmittedComponent.qml", root);
        var c1 = comp.createObject(null); // JS ownership
        c1.onAChanged.connect(c2.c1aChangedHandler);
        c1HasBeenDestroyed = true; // gc will collect c1.
        // return to event loop.
    }

    function destroyC2() {
        // we must gc() c1 first, then destroy c2, then handle events.
        c2.destroy();
    }
}