Timer QML Type

Triggers a handler at a specified interval. 更多...

导入语句: import QtQuick .

特性

信号

方法

详细描述

A Timer can be used to trigger an action either once, or repeatedly at a given interval. It wraps Qul::Timer .

Here is a Timer that shows the current date and time, and updates the text every 500 milliseconds.

import QtQuick 2.15
Rectangle {
    color: "white"
    property int counter: 0
    Timer {
        interval: 500; running: true; repeat: true
        onTriggered: counter += 1
    }
    Text { id: label; text: counter }
}
						

The Timer type is synchronized with the animation timer. As the animation timer is usually set to 60fps, the resolution of Timer will be at best 16ms.

特性文档编制

interval : int

设置 interval between triggers, in milliseconds.

The default interval is 1000 milliseconds.


repeat : bool

The timer is triggered repeatedly at the specified interval, if repeat is true ; otherwise, it is triggered once at the specified interval and then stopped by setting running to false .

注意: It is set to false 在默认情况下。

另请参阅 running .


running : bool

若设为 true , starts the timer; otherwise stops the timer. For a non-repeating timer, running 被设为 false after the timer has been triggered.

注意: It is set to false 在默认情况下。

另请参阅 repeat .


信号文档编制

triggered ()

This signal is emitted when the Timer times out.

注意: 相应处理程序是 onTriggered .


方法文档编制

restart ()

Restarts the timer

The Timer is started if it is not running, otherwise it is stopped, reset to its initial state, and started. The running property is set to true after calling restart() .


start ()

Starts the timer

If the timer is already running, calling this method has no effect. The running property is set to true after calling start() .


stop ()

Stops the timer

If the timer is not running, calling this method has no effect. The running property is set to false after calling stop() .