aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlqt/data/later.qml
blob: a90f3aba9f272e4fe143e157c2b1fc16fc68c97c (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import QtQuick 2.0
import LaterImports 1.0

Row {
    id: row
    Repeater {
        id: repeater
        model: 5
        delegate: Item { }
    }

    property bool test1_1: false
    property bool test1_2: row.focus
    property bool test2_1: false
    property bool test2_2: (firstFunctionCallCounter == 1 && secondFunctionCallCounter == 1 && signalCallCounter == 1)

    property int firstFunctionCallCounter: 0
    property int secondFunctionCallCounter: 0
    property int signalCallCounter: 0

    signal testSignal
    onTestSignal: {
        signalCallCounter++;
    }

    onChildrenChanged: {
        Qt.callLater(row.forceActiveFocus); // built-in function
        Qt.callLater(row.firstFunction);    // JS function
        Qt.callLater(row.testSignal);       // signal
    }

    function firstFunction() {
        firstFunctionCallCounter++;
    }

    function secondFunction() {
        secondFunctionCallCounter++;
    }

    Component.onCompleted: {
        test1_1 = !row.focus;
        test2_1 = (firstFunctionCallCounter == 0);

        Qt.callLater(secondFunction);
        Qt.callLater(firstFunction);
        Qt.callLater(secondFunction);
    }

    function test2() {
        repeater.model = 2;
    }

    function test3() {
        Qt.callLater(test3_recursive);
    }

    property int recursion: 0
    property bool test3_1: (recursion == 1)
    property bool test3_2: (recursion == 2)
    property bool test3_3: (recursion == 3)
    function test3_recursive() {
        if (recursion < 3) {
            Qt.callLater(test3_recursive);
            Qt.callLater(test3_recursive);
        }
        recursion++;
    }

    function test4() {
        Qt.callLater(functionThatDoesNotExist);
    }

    property bool test5_1: false
    function test5() {
        Qt.callLater(functionWithArguments, "THESE", "ARGS", "WILL", "BE", "OVERWRITTEN")
        Qt.callLater(functionWithArguments, "firstArg", 2, "thirdArg")
    }

    function functionWithArguments(firstStr, secondInt, thirdString) {
        test5_1 = (firstStr == "firstArg" && secondInt == 2 && thirdString == "thirdArg");
    }


    property bool test6_1: (callOrder_Later == "TWO THREE ") // not "THREE TWO "
    function test6() {
        Qt.callLater(test6Function1, "ONE");
        Qt.callLater(test6Function2, "TWO");
        Qt.callLater(test6Function1, "THREE");
    }

    property string callOrder_Later
    function test6Function1(arg) { callOrder_Later += arg + " "; }
    function test6Function2(arg) { callOrder_Later += arg + " "; }

    property int test9_1: SingletonType.intProp;
    function test9() {
        SingletonType.resetIntProp();
        Qt.callLater(SingletonType.testFunc)
        Qt.callLater(SingletonType.testFunc)
        Qt.callLater(SingletonType.testFunc)
        Qt.callLater(SingletonType.testFunc)
        // should only get called once.
    }

    property int test10_1: 0
    function test10() {
        var c = Qt.createComponent("LaterComponent.qml");
        var obj = c.createObject(); // QML ownership.
        Qt.callLater(obj.testFn);
        // note: obj will be cleaned up during next gc().
    }

    property int test11_1: 0
    function test11() {
        var c = Qt.createComponent("LaterComponent2.qml");
        var obj = c.createObject(); // QML ownership.
        Qt.callLater(obj.testFn);
        gc(); // this won't actually collect the obj, we need to trigger gc manually in the test.
    }

    function test14() {
        Qt.callLater(console.log, "success")
    }
}