Class Timer.

Inherits Garbage

The Timer class provides a way to ask for one callback at a time of your choosing, or for regular callbacks at a specified intervals. The default is one callback; calling setRepeating() changes that.

The class provides second resolution, nothing better. Creating a timer with delay/interval of 1 provides the first callback after 1-2 seconds and (if repeating() is true) at 1-second intervals thereafter.

If the system is badly overloaded, callbacks may be skipped. There never is more than one activation pending for a single Timer.

Timer::Timer( EventHandler * owner, uint delay )

Constructs an timer which will notify owner after delay seconds, or slightly more.

bool Timer::active() const

Returns true if this timer will call the EventHandler::execute() function of owner() at some point, and falls if it will not.

In particular, if it is presently calling EventHandler::execute() and will not do it again in the future, so it returns false.

void Timer::execute()

Called by the EventLoop when this Timer should notify its owner().

void Timer::notify()

This function notifies the owner of this Timer's expiration.

EventHandler * Timer::owner()

Returns a pointer to the the EventHandler object that this Timer will notify.

bool Timer::repeating() const

Returns true if this Timer will notify its owner at regular intervals, and false if it notifies its owner just once. The initial value is false.

void Timer::setRepeating( bool r )

Makes this Timer notify its owner at regular intervals if r is true, and just once (more) if r is false.

The initial value is false. If you call setRepeating( false ) on an existing timer, it will be executed once more and then be freed.

uint Timer::timeout() const

Returns the time (as an integer number of seconds increasing towards the future) at which this Timer will call EventHandler::execute(), or 0 if it is not active().


Kills this timer right now, preventing any future callbacks.

This web page based on source code belonging to The Archiveopteryx Developers. All rights reserved.