Difference between revisions of "Development/Tutorials/Plasma4/JavaScript/API-Timers"

Jump to: navigation, search
(Created page with '= QTimer = Read-write properties: * ''boolean'' '''active''': true if active, false if not * ''boolean'' '''singleShot''': true if the timer will fire once when started, false i...')
 
(An example for QTimer.)
 
(One intermediate revision by one other user not shown)
Line 13: Line 13:
 
Signals:
 
Signals:
 
* '''timeout()''': this signal is emitted whenever the timer interval is reached
 
* '''timeout()''': this signal is emitted whenever the timer interval is reached
 +
 +
 +
 +
See the [http://doc.qt.io/qt-4.8/qml-timer.html Timer QML Element] at the Qt documentation web.
 +
 +
== Example ==
 +
You can use the Timer at the QML file like this:
 +
 +
<syntaxhighlight lang="javascript" line>
 +
import QtQuick 1.1
 +
import org.kde.plasma.components 0.1 as PComp
 +
import "../code/load_web.js" as LoadWeb
 +
 +
Item {
 +
 +
    ...
 +
 +
    Timer {
 +
        id: ensure_loaded_timer
 +
        interval: 10000
 +
        onTriggered: LoadWeb.update_list()
 +
        repeat: true
 +
        running: true
 +
    }
 +
}
 +
</syntaxhighlight>
 +
 +
Then you can use the timer on your Javascript code using the timer's id.

Latest revision as of 01:23, 2 March 2015

QTimer

Read-write properties:

  • boolean active: true if active, false if not
  • boolean singleShot: true if the timer will fire once when started, false if it will fire repeatedly until stopped
  • boolean interval: the interval in milliseconds that the timer will trigger

Functions:

  • start(int msec): starts the timer with msec as the interval
  • start(): starts the timer with the default interval
  • stop(): stops the timer

Signals:

  • timeout(): this signal is emitted whenever the timer interval is reached


See the Timer QML Element at the Qt documentation web.

Example

You can use the Timer at the QML file like this:

 1 import QtQuick 1.1
 2 import org.kde.plasma.components 0.1 as PComp
 3 import "../code/load_web.js" as LoadWeb
 4 
 5 Item { 
 6 
 7     ...
 8 
 9     Timer {
10         id: ensure_loaded_timer
11         interval: 10000
12         onTriggered: LoadWeb.update_list()
13         repeat: true
14         running: true
15     }
16 }

Then you can use the timer on your Javascript code using the timer's id.


This page was last edited on 2 March 2015, at 01:23. Content is available under Creative Commons License SA 4.0 unless otherwise noted.