Development/Tutorials/Plasma4/JavaScript/API-Timers

From KDE TechBase
Revision as of 01:23, 2 March 2015 by Cgimenez (talk | contribs) (An example for QTimer.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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:

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
    }
}

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