Javascript Qml中带延迟的循环
我尝试了互联网上几乎所有的解决方案,但都不管用。我想创建一个while(true)循环,每次迭代延迟约20毫秒 计时器是一种更好的方法:Javascript Qml中带延迟的循环,javascript,qt,qml,delay,Javascript,Qt,Qml,Delay,我尝试了互联网上几乎所有的解决方案,但都不管用。我想创建一个while(true)循环,每次迭代延迟约20毫秒 计时器是一种更好的方法: ApplicationWindow { id: window width: 320 height: 260 visible: true Timer { id: timer interval: 20 running: false repeat: true
ApplicationWindow {
id: window
width: 320
height: 260
visible: true
Timer {
id: timer
interval: 20
running: false
repeat: true
property int returnedValue: 0
onTriggered: {
console.log("Loop iteration every 20ms");
returnedValue = 12;
}
onReturnedValueChanged: {
timer.stop();
console.log("Stop loop wth:", returnedValue);
}
}
function startTimer() {
timer.running = true;
}
Button {
text: "Click me"
onClicked: startTimer()
}
}
非常感谢你。我怎样才能打破计时器?好的,我找到了。但是如何调用函数中的计时器。我已经更新了我的示例。计时器现在在函数
startTimer
中启动。非常感谢。如果特定变量不是0,我希望返回一个值。如何从计时器返回值?最简单的方法是将值存储在属性中并停止计时器。