#include <Wt/WTimer>
Public Member Functions | |
WTimer (WObject *parent=0) | |
Construct a new timer with the given parent. | |
~WTimer () | |
Destuctor. | |
int | interval () const |
Get the interval (msec). | |
void | setInterval (int msec) |
Set the interval (msec). | |
bool | isActive () const |
Return if the timer is running. | |
bool | isSingleShot () const |
Is this timer set to fire only once. | |
void | setSingleShot (bool singleShot) |
Configure this timer to fire only once. | |
void | start () |
Start the timer. | |
void | stop () |
Stop the timer. | |
EventSignal< WMouseEvent > & | timeout () |
Signal emitted when the timer timeouts. | |
Static Public Member Functions | |
template<class T, class V> | |
static void | singleShot (int msec, T *receiver, void(V::*method)()) |
This static function calls a slot after a given time interval. |
To use a timer, create a WTimer instance, set the timer interval using setInterval() and connect a slot to the timeout signal. Then, start the timer using start(). An active timer may be cancelled at any time using stop().
By default, a timer will continue to generate events until you stop() it. To create a timer that will fire only once, use setSingleShot().
There is also a convience static method singleShot().
When connecting stateless slot implementations to the timeout signal, these stateless slot implementations will be used as for any other signal (when Ajax is available).
In clients without (enabled) JavaScript support, the minimum resolution of the timer is one second (1000 milli-seconds), and it is probably wise to use timers sparingly.
Timers are one way to provide updates of a web page without the user generating an event. Alternatively you may consider server-initiated updates, see WApplication::enableUpdates().
Usage example:
// setup a timer which calls MyClass::timeout() every 2 seconds, until timer->stop() is called. Wt::WTimer *timer = new Wt::WTimer(); timer->setInterval(2000); timer->timeout().connect(SLOT(this, MyClass::timeout)); timer->start();
void Wt::WTimer::setSingleShot | ( | bool | singleShot | ) |
Configure this timer to fire only once.
A Timer is by default not single shot, and will fire continuously, until it is stopped.
void Wt::WTimer::singleShot | ( | int | msec, | |
T * | receiver, | |||
void(V::*)() | method | |||
) | [inline, static] |
This static function calls a slot after a given time interval.
For example, the following code will call this->doSome() after 2 seconds:
WTimer::singleShot(2000, SLOT(this, MyClass::doSome));
void Wt::WTimer::start | ( | ) |
Start the timer.
The timer will be isActive(), until either the interval has elapsed, after which the timeout signal is activated, or until stop() is called.
void Wt::WTimer::stop | ( | ) |
EventSignal< WMouseEvent > & Wt::WTimer::timeout | ( | ) |
Signal emitted when the timer timeouts.
The WMouseEvent does not provide any meaningful information but is an implementation artefact.