glibmm 2.46.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Examples

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Glib::SignalTimeout Class Reference
The Main Event Loop

`#include <glibmm/main.h>`

## Public Member Functions

sigc::connection | connect (const sigc::slot< bool >& slot, unsigned int interval, int priority=PRIORITY_DEFAULT)
| Connects a timeout handler. More...
void | connect_once (const sigc::slot< void >& slot, unsigned int interval, int priority=PRIORITY_DEFAULT)
| Connects a timeout handler that runs only once. More...
sigc::connection | connect_seconds (const sigc::slot< bool >& slot, unsigned int interval, int priority=PRIORITY_DEFAULT)
| Connects a timeout handler with whole second granularity. More...
void | connect_seconds_once (const sigc::slot< void >& slot, unsigned int interval, int priority=PRIORITY_DEFAULT)
| Connects a timeout handler that runs only once with whole second granularity. More...

## Member Function Documentation

sigc::connection Glib::SignalTimeout::connect | ( | const sigc::slot< bool > & | slot,
|  | unsigned int | interval,
|  | int | priority = `PRIORITY_DEFAULT`
| ) |  |

Connects a timeout handler.

Note that timeout functions may be delayed, due to the processing of other event sources. Thus they should not be relied on for precise timing. After each call to the timeout function, the time of the next timeout is recalculated based on the current time and the given interval (it does not try to 'catch up' time lost in delays).

If you want to have a timer in the "seconds" range and do not care about the exact time of the first call of the timer, use the connect_seconds() function; this function allows for more optimizations and more efficient system power usage.

bool timeout_handler() { ... }
Glib::signal_timeout().connect(sigc::ptr_fun(&timeout_handler), 1000);

is equivalent to:

bool timeout_handler() { ... }
const auto timeout_source = Glib::TimeoutSource::create(1000);
timeout_source->connect(sigc::ptr_fun(&timeout_handler));
timeout_source->attach(Glib::MainContext::get_default());

This method is not thread-safe. You should call it, or manipulate the returned sigc::connection object, only from the thread where the SignalTimeout object's MainContext runs.

Parameters

  slot | A slot to call when interval has elapsed. If `timeout_handler()` returns `false` the handler is disconnected.
  interval | The timeout in milliseconds.
  priority | The priority of the new event source.

Returns
  A connection handle, which can be used to disconnect the handler.

void Glib::SignalTimeout::connect_once | ( | const sigc::slot< void > & | slot,
|  | unsigned int | interval,
|  | int | priority = `PRIORITY_DEFAULT`
| ) |  |

Connects a timeout handler that runs only once.

This method takes a function pointer to a function with a void return and no parameters. After running once it is not called again.

Because sigc::trackable is not thread-safe, if the slot represents a non-static method of a class deriving from sigc::trackable, and the slot is created by sigc::mem_fun(), connect_once() should only be called from the thread where the SignalTimeout object's MainContext runs. You can use, say, boost::bind() or, in C++11, std::bind() or a C++11 lambda expression instead of sigc::mem_fun().

See also
  connect()

Parameters

  slot | A slot to call when interval has elapsed. For example: void on_timeout_once()
  interval | The timeout in milliseconds.
  priority | The priority of the new event source.

sigc::connection Glib::SignalTimeout::connect_seconds | ( | const sigc::slot< bool > & | slot,
|  | unsigned int | interval,
|  | int | priority = `PRIORITY_DEFAULT`
| ) |  |

Connects a timeout handler with whole second granularity.

Unlike connect(), this operates at whole second granularity. The initial starting point of the timer is determined by the implementation and the implementation is expected to group multiple timers together so that they fire all at the same time.

To allow this grouping, the interval to the first timer is rounded and can deviate up to one second from the specified interval. Subsequent timer iterations will generally run at the specified interval.

bool timeout_handler() { ... }
Glib::signal_timeout().connect_seconds(sigc::ptr_fun(&timeout_handler), 5);

is equivalent to:

bool timeout_handler() { ... }
const auto timeout_source = Glib::TimeoutSource::create(5000);
timeout_source->connect(sigc::ptr_fun(&timeout_handler));
timeout_source->attach(Glib::MainContext::get_default());

This method is not thread-safe. You should call it, or manipulate the returned sigc::connection object, only from the thread where the SignalTimeout object's MainContext runs.

Parameters

  slot | A slot to call when interval has elapsed. If `timeout_handler()` returns `false` the handler is disconnected.
  interval | The timeout in seconds.
  priority | The priority of the new event source.

Returns
  A connection handle, which can be used to disconnect the handler.

Since glibmm 2.14:

void Glib::SignalTimeout::connect_seconds_once | ( | const sigc::slot< void > & | slot,
|  | unsigned int | interval,
|  | int | priority = `PRIORITY_DEFAULT`
| ) |  |

Connects a timeout handler that runs only once with whole second granularity.

This method takes a function pointer to a function with a void return and no parameters. After running once it is not called again.

Because sigc::trackable is not thread-safe, if the slot represents a non-static method of a class deriving from sigc::trackable, and the slot is created by sigc::mem_fun(), connect_seconds_once() should only be called from the thread where the SignalTimeout object's MainContext runs. You can use, say, boost::bind() or, in C++11, std::bind() or a C++11 lambda expression instead of sigc::mem_fun().

See also
  connect_seconds()

Parameters

  slot | A slot to call when interval has elapsed. For example: void on_timeout_once()
  interval | The timeout in seconds.
  priority | The priority of the new event source.