1
0
mirror of https://github.com/jaredtao/TaoQuick.git synced 2025-01-19 20:22:56 +08:00

add CallLatter

This commit is contained in:
jared 2019-12-13 13:33:37 +08:00
parent b437c1ed10
commit db18cc1e2b
2 changed files with 41 additions and 0 deletions

View File

@ -47,5 +47,6 @@
<file>Qml/EffectComponent/Shapes/TRoundRect.qml</file>
<file>Qml/EffectComponent/TCommon.qml</file>
<file>Qml/EffectComponent/TShaderToy.qml</file>
<file>Qml/BasicComponent/Others/CallLatter.qml</file>
</qresource>
</RCC>

View File

@ -0,0 +1,40 @@
import QtQuick 2.12
QtObject {
Component {
id: timerComp
Timer {
id: timer
repeat: false
property var _cb: function() {}
onTriggered: {
_cb()
destroy(parent)
}
function setTimeout(callback, delayTime) {
_cb = callback;
interval = delayTime;
start();
}
}
}
function callLatter(callback, delayTime) {
// if (Qt.callLater) {
// Qt.callLater(callback)
// } else {
let timerObj = timerComp.createObject()
timerObj.setTimeout(callback, delayTime)
// }
}
Component.onCompleted: {
callLatter(function() {
console.log("0")
}, 0)
callLatter(function() {
console.log("100")
}, 100)
callLatter(function() {
console.log("50")
}, 50)
}
}