Timer¶
Description¶
The Timer object implements a timer which triggers periodically or only once. Property repeat controls the behaviour.
› Inherits: | Object |
---|
Properties¶
interval¶
This property holds the interval which elapses before triggered() is emitted. The minimum value is 1
.
› Type: | SignedInteger |
---|---|
› Default: | 0 |
› Signal: | intervalChanged() |
› Attributes: | Writable |
msecsElapsed¶
This property holds returns the number of milliseconds since this timer was last started.
› Type: | SignedBigInteger |
---|---|
› Signal: | msecsElapsedChanged() |
› Attributes: | Readonly |
repeat¶
This property holds whether the timer triggers only once (repeat set to false
) or repeatedly.
› Type: | Boolean |
---|---|
› Default: | true |
› Signal: | repeatChanged() |
› Attributes: | Writable |
running¶
This property holds whether the timer is running. Setting this property equals to calling start() or stop().
› Type: | Boolean |
---|---|
› Default: | true |
› Signal: | runningChanged() |
› Attributes: | Writable |
synchronize¶
This property holds whether the timer should be synchronized to the system clock. When synchronized the actual timer start will be delayed such that the trigger time is a multiple of interval beginning at midnight UTC.
This property was introduced in InCore 2.7.
› Type: | Boolean |
---|---|
› Default: | false |
› Signal: | synchronizeChanged() |
› Attributes: | Writable |
timestamp¶
This property holds a timestamp in milliseconds of the last triggered() signal emission.
This property was introduced in InCore 2.7.
› Type: | SignedBigInteger |
---|---|
› Signal: | timestampChanged() |
› Attributes: | Readonly |
triggeredOnStart¶
This property holds whether the timer sends a triggered() signal when the timer is started.
› Type: | Boolean |
---|---|
› Default: | false |
› Signal: | triggeredOnStartChanged() |
› Attributes: | Writable |
triggeredOnStop¶
This property holds whether the timer sends a triggered() signal after the timer is stopped.
› Type: | Boolean |
---|---|
› Default: | false |
› Signal: | triggeredOnStopChanged() |
› Attributes: | Writable |
Methods¶
restart()¶
This method restarts the timer. This is the same as calling stop() and start() consecutively.
singleShot(SignedInteger msec, JSValue method)¶
This method calls the given method (e.g. lambda) after the specified number of milliseconds.
This method was introduced in InCore 2.7.
Signals¶
Example¶
import InCore.Foundation 2.7
Application {
onCompleted: {
testTimer.singleShot(5000, () => { console.log("I was called through Timer.singleShot()") })
}
//minimal Timer with default values
Timer {
onTriggered: console.log( "i am a minimal Timer" )
}
Timer {
repeat: false
interval: 10000
onTriggered: console.log( "i trigger only once after a while" )
}
Timer {
id: testTimer
interval: 500
onTriggered: console.log( "i am running fast" )
}
Timer {
id: onOffTimer
interval: 2000
onTriggered: {
console.log( "switching testTimer", testTimer.running ? "off" : "on" )
testTimer.running = !testTimer.running
}
}
}