mirror of
https://github.com/jaredtao/TaoQuick.git
synced 2025-01-19 20:22:56 +08:00
add CallLatter
This commit is contained in:
parent
b437c1ed10
commit
db18cc1e2b
@ -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>
|
||||
|
40
src/TaoQuick/Qml/BasicComponent/Others/CallLatter.qml
Normal file
40
src/TaoQuick/Qml/BasicComponent/Others/CallLatter.qml
Normal 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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user