| 1 |
import QtQuick 2.0 |
| 2 |
import LaterImports 1.0 |
| 3 |
|
| 4 |
Row { |
| 5 |
id: row |
| 6 |
Repeater { |
| 7 |
id: repeater |
| 8 |
model: 5 |
| 9 |
delegate: Item { } |
| 10 |
} |
| 11 |
|
| 12 |
property bool test1_1: false |
| 13 |
property bool test1_2: row.focus |
| 14 |
property bool test2_1: false |
| 15 |
property bool test2_2: (firstFunctionCallCounter == 1 && secondFunctionCallCounter == 1 && signalCallCounter == 1) |
| 16 |
|
| 17 |
property int firstFunctionCallCounter: 0 |
| 18 |
property int secondFunctionCallCounter: 0 |
| 19 |
property int signalCallCounter: 0 |
| 20 |
|
| 21 |
signal testSignal |
| 22 |
onTestSignal: { |
| 23 |
signalCallCounter++; |
| 24 |
} |
| 25 |
|
| 26 |
onChildrenChanged: { |
| 27 |
Qt.callLater(row.forceActiveFocus); // built-in function |
| 28 |
Qt.callLater(row.firstFunction); // JS function |
| 29 |
Qt.callLater(row.testSignal); // signal |
| 30 |
} |
| 31 |
|
| 32 |
function firstFunction() { |
| 33 |
firstFunctionCallCounter++; |
| 34 |
} |
| 35 |
|
| 36 |
function secondFunction() { |
| 37 |
secondFunctionCallCounter++; |
| 38 |
} |
| 39 |
|
| 40 |
Component.onCompleted: { |
| 41 |
test1_1 = !row.focus; |
| 42 |
test2_1 = (firstFunctionCallCounter == 0); |
| 43 |
|
| 44 |
Qt.callLater(secondFunction); |
| 45 |
Qt.callLater(firstFunction); |
| 46 |
Qt.callLater(secondFunction); |
| 47 |
} |
| 48 |
|
| 49 |
function test2() { |
| 50 |
repeater.model = 2; |
| 51 |
} |
| 52 |
|
| 53 |
function test3() { |
| 54 |
Qt.callLater(test3_recursive); |
| 55 |
} |
| 56 |
|
| 57 |
property int recursion: 0 |
| 58 |
property bool test3_1: (recursion == 1) |
| 59 |
property bool test3_2: (recursion == 2) |
| 60 |
property bool test3_3: (recursion == 3) |
| 61 |
function test3_recursive() { |
| 62 |
if (recursion < 3) { |
| 63 |
Qt.callLater(test3_recursive); |
| 64 |
Qt.callLater(test3_recursive); |
| 65 |
} |
| 66 |
recursion++; |
| 67 |
} |
| 68 |
|
| 69 |
function test4() { |
| 70 |
Qt.callLater(functionThatDoesNotExist); |
| 71 |
} |
| 72 |
|
| 73 |
property bool test5_1: false |
| 74 |
function test5() { |
| 75 |
Qt.callLater(functionWithArguments, "THESE", "ARGS", "WILL", "BE", "OVERWRITTEN") |
| 76 |
Qt.callLater(functionWithArguments, "firstArg", 2, "thirdArg") |
| 77 |
} |
| 78 |
|
| 79 |
function functionWithArguments(firstStr, secondInt, thirdString) { |
| 80 |
test5_1 = (firstStr == "firstArg" && secondInt == 2 && thirdString == "thirdArg"); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
property bool test6_1: (callOrder_Later == "TWO THREE ") // not "THREE TWO " |
| 85 |
function test6() { |
| 86 |
Qt.callLater(test6Function1, "ONE"); |
| 87 |
Qt.callLater(test6Function2, "TWO"); |
| 88 |
Qt.callLater(test6Function1, "THREE"); |
| 89 |
} |
| 90 |
|
| 91 |
property string callOrder_Later |
| 92 |
function test6Function1(arg) { callOrder_Later += arg + " "; } |
| 93 |
function test6Function2(arg) { callOrder_Later += arg + " "; } |
| 94 |
|
| 95 |
property int test9_1: SingletonType.intProp; |
| 96 |
function test9() { |
| 97 |
SingletonType.resetIntProp(); |
| 98 |
Qt.callLater(SingletonType.testFunc) |
| 99 |
Qt.callLater(SingletonType.testFunc) |
| 100 |
Qt.callLater(SingletonType.testFunc) |
| 101 |
Qt.callLater(SingletonType.testFunc) |
| 102 |
// should only get called once. |
| 103 |
} |
| 104 |
|
| 105 |
property int test10_1: 0 |
| 106 |
function test10() { |
| 107 |
var c = Qt.createComponent("LaterComponent.qml"); |
| 108 |
var obj = c.createObject(); // QML ownership. |
| 109 |
Qt.callLater(obj.testFn); |
| 110 |
// note: obj will be cleaned up during next gc(). |
| 111 |
} |
| 112 |
|
| 113 |
property int test11_1: 0 |
| 114 |
function test11() { |
| 115 |
var c = Qt.createComponent("LaterComponent2.qml"); |
| 116 |
var obj = c.createObject(); // QML ownership. |
| 117 |
Qt.callLater(obj.testFn); |
| 118 |
gc(); // this won't actually collect the obj, we need to trigger gc manually in the test. |
| 119 |
} |
| 120 |
|
| 121 |
function test14() { |
| 122 |
Qt.callLater(console.log, "success") |
| 123 |
} |
| 124 |
} |