gpt4 book ai didi

QTimer::singleShot等效于QML

转载 作者:行者123 更新时间:2023-12-04 03:03:56 32 4
gpt4 key购买 nike

考虑以下C++语句(示例from docs):

QTimer::singleShot(600000, &app, SLOT(quit()));

如何在.qml JavaScript中执行相同的操作,例如QML:
Rectangle {
property int counter: 0
onCounterChanged: {
if (counter > 42) {
// do equivalent of above C++ statement here
}
}
// more code, which actually manipulates counter
}

有一个明显的解决方案,即拥有单独的 Timer,然后由此JavaScript代码启动,如果无法实现单行代码,我将接受它作为答案。是吗?

最佳答案

将Timer对象的“repeat”属性更改为false。

import QtQuick 1.0

Item {
Timer {
id: timer
interval: 600000
running: false
repeat: false
onTriggered: Qt.quit()
}

Rectangle {
property int counter: 0
onCounterChanged: {
if (counter > 42) {
timer.running = true
}
}
}
}

关于QTimer::singleShot等效于QML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30754412/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com