glibmm 2.78.1
Public Member Functions | List of all members
Glib::SignalIdle Class Reference

#include <glibmm/main.h>

Public Member Functions

sigc::connection connect (const sigc::slot< bool()> & slot, int priority=PRIORITY_DEFAULT_IDLE)
 Connects an idle handler. More...
 
void connect_once (const sigc::slot< void()> & slot, int priority=PRIORITY_DEFAULT_IDLE)
 Connects an idle handler that runs only once. More...
 

Member Function Documentation

◆ connect()

sigc::connection Glib::SignalIdle::connect ( const sigc::slot< bool()> &  slot,
int  priority = PRIORITY_DEFAULT_IDLE 
)

Connects an idle handler.

bool idle_handler() { ... }
pointer_to_unary_function< _Arg, _Result > ptr_fun(_Result(*__x)(_Arg))
sigc::connection connect(const sigc::slot< bool()> &slot, int priority=PRIORITY_DEFAULT_IDLE)
Connects an idle handler.
SignalIdle signal_idle()
Convenience idle signal.

is equivalent to:

bool idle_handler() { ... }
const auto idle_source = Glib::IdleSource::create();
idle_source->connect(sigc::ptr_fun(&idle_handler));
idle_source->attach(Glib::MainContext::get_default());
static Glib::RefPtr< IdleSource > create()
static Glib::RefPtr< MainContext > get_default()
Returns the global default main context.

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

Parameters
slotA slot to call when the main loop is idle. If idle_handler() returns false the handler is disconnected.
priorityThe priority of the new event source.
Returns
A connection handle, which can be used to disconnect the handler.

◆ connect_once()

void Glib::SignalIdle::connect_once ( const sigc::slot< void()> &  slot,
int  priority = PRIORITY_DEFAULT_IDLE 
)

Connects an idle 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 SignalIdle 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
slotA slot to call when the main loop is idle. For example:
void on_idle_once()
priorityThe priority of the new event source.
Examples
thread/dispatcher.cc.