Timer Class Reference

#include <Pt/System/Timer.h>

Notifies clients in constant intervals. More...

Public Member Functions

 Timer ()
 Default constructor. More...
 ~Timer ()
 Destructor. More...
void detach ()
 Detach from used event loop.
std::size_t interval () const
 Returns the current timer interval in milliseconds.
bool isStarted () const
 Returs true if timer was started.
EventLooploop ()
 Returns the used event loop.
void setActive (EventLoop &loop)
 Sets the used event loop.
void start (std::size_t interval)
 Starts the timer. More...
void stop ()
 Stops the timer. More...
Signaltimeout ()
 Notifies about interval timeouts. More...

Detailed Description

Timers can be used to be notified if a time interval expires. It usually works with an event loop, where the Timer needs to be registered. Timers send the timeout signal in given intervals, to which the interested clients connect. The interval can be changed at any time and timers can switch between an active and inactive state.

The following code calls the function onTimer every second:

void onTimer()
std::cerr << "Time out!\n";
int main()
timer.timeout() += Pt::slot(onTimer);
return 0;

Constructor & Destructor Documentation

Timer ( )

Constructs an inactive timer.

~Timer ( )

The destructor sends the destroyed signal.

Member Function Documentation

void start ( std::size_t  interval)

Start a timer from the moment this method is called. The Timer needs to be registered with an event loop, otherwise the timeout signal will not be sent.

intervalTimeout interval in milliseconds
void stop ( )

If the Timer is registered with an event loop, the timout signal will not be sent anymore.

Signal& timeout ( )

This signal is sent if the interval time has expired.