第八章:QML定时器Timer

QML中实现方法

定时器Timer介绍:https://doc.qt.io/qt-5/qml-qtqml-timer.html

import QtQuick 2.6
import QtQuick.Window 2.2

Window {
    visible: true
    width: 500
    height: 60
    title: qsTr("定时器")
    Timer {
        interval: 500  //设置定时器定时时间为500ms,默认1000ms
        running: true  //是否开启定时,默认是false,当为true的时候,进入此界面就开始定时
        repeat: true   //是否重复定时,默认为false
        onTriggered: time.text = Date().toString() //定时触发槽,定时完成一次就进入一次
    }

    Text {
        id: time
        verticalAlignment: Text.AlignVCenter
        anchors.top: parent.top
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.topMargin: 20
    }
}

C++中实现方法

参考第5章,C++中调用QML交互

猜你喜欢

转载自blog.csdn.net/qq_40602000/article/details/109277517