libsigc++  3.6.0
Classes | Functions
Signals

Use sigc::signal::connect() or sigc::signal::connect_first() with sigc::mem_fun() and sigc::ptr_fun() to connect a method or function with a signal. More...

Classes

struct  sigc::connection
 Convenience class for safe disconnection. More...
 
struct  sigc::scoped_connection
 Convenience class for safe disconnection, including automatic disconnection upon destruction. More...
 
class  sigc::signal< T_return(T_arg...)>
 signal can be used to connect() slots that are invoked during subsequent calls to emit(). More...
 
class  sigc::signal< T_return(T_arg...)>::accumulated< T_accumulator >
 Like sigc::signal but the additional template parameter T_accumulator defines the accumulator type that should be used. More...
 
struct  sigc::signal_base
 Base class for the sigc::signal template. More...
 
class  sigc::signal_with_accumulator< T_return, T_accumulator, T_arg >
 Signal declaration. More...
 
struct  sigc::trackable
 Base class for objects with auto-disconnection. More...
 
class  sigc::trackable_signal< T_return(T_arg...)>
 trackable_signal can be used to connect() slots that are invoked during subsequent calls to emit(). More...
 
class  sigc::trackable_signal< T_return(T_arg...)>::accumulated< T_accumulator >
 Like sigc::trackable_signal but the additional template parameter T_accumulator defines the accumulator type that should be used. More...
 
class  sigc::trackable_signal_with_accumulator< T_return, T_accumulator, T_arg >
 Signal declaration. More...
 

Functions

template<typename T_return , typename T_obj , typename... T_arg>
connection sigc::signal_connect (signal< T_return(T_arg...)> & signal, const T_obj & obj, T_return(T_obj::* fun)(T_arg...) const)
 Connect a const method to a signal. More...
 
template<typename T_return , typename T_obj , typename... T_arg>
connection sigc::signal_connect (signal< T_return(T_arg...)> & signal, T_obj & obj, T_return(T_obj::* fun)(T_arg...))
 Connect a non-const method to a signal. More...
 
template<typename T_return , typename... T_arg>
connection sigc::signal_connect (signal< T_return(T_arg...)> & signal, T_return(* fun)(T_arg...))
 Connect a function to a signal. More...
 

Detailed Description

Use sigc::signal::connect() or sigc::signal::connect_first() with sigc::mem_fun() and sigc::ptr_fun() to connect a method or function with a signal.

signal_clicked.connect( sigc::mem_fun(*this, &MyWindow::on_clicked) );
decltype(auto) mem_fun(T_return(T_obj::*func)(T_arg...))
Creates a functor of type sigc::mem_functor which wraps a method.
Definition: mem_fun.h:188

When the signal is emitted your method will be called.

signal::connect() returns a connection, which you can later use to disconnect your method. If the type of your object inherits from sigc::trackable the method is disconnected automatically when your object is destroyed.

When signals are copied they share the underlying information, so you can have a protected/private sigc::signal member and a public accessor method. A sigc::signal is a kind of reference-counting pointer. It's similar to std::shared_ptr<>, although sigc::signal is restricted to holding a pointer to a sigc::internal::signal_impl object that contains the implementation of the signal.

class MyClass
{
public:
using MySignalType = sigc::signal<void()>;
MySignalType get_my_signal() { return m_my_signal; }
private:
MySignalType m_my_signal;
};

signal and slot objects provide the core functionality of this library. A slot is a container for an arbitrary functor. A signal is a list of slots that are executed on emission. For compile time type safety a list of template arguments must be provided for the signal template that determines the parameter list for emission. Functors and closures are converted into slots implicitly on connection, triggering compiler errors if the given functor or closure cannot be invoked with the parameter list of the signal to connect to.

Almost any functor with the correct signature can be converted to a sigc::slot and connected to a signal. See Slots and sigc::signal::connect().

Use sigc::signal_connect() to connect a method or function to a signal without having to explicitly write the required template parameters in case of method or function overloading.

sigc::signal<void(int)> sig;
void fun(int);
void fun(double);
sig.connect(sigc::ptr_fun<void, int>(fun));
// or more simply:
connection signal_connect(signal< T_return(T_arg...)> &signal, T_return(*fun)(T_arg...))
Connect a function to a signal.
Definition: signal_connect.h:40

It can also be used as a replacement for calling signal::connect() with a sigc::mem_fun() or a sigc::ptr_fun().

Function Documentation

◆ signal_connect() [1/3]

template <typename T_return , typename T_obj , typename... T_arg>
connection sigc::signal_connect ( signal< T_return(T_arg...)> &  signal,
const T_obj &  obj,
T_return(T_obj::*)(T_arg...) const  fun 
)
inline

Connect a const method to a signal.

Parameters
signalThe signal to connect to.
objReference to object instance the functor should operate on.
funPointer to method that should be wrapped.
Returns
A connection.
Since libsigc++ 3.8:

◆ signal_connect() [2/3]

template <typename T_return , typename T_obj , typename... T_arg>
connection sigc::signal_connect ( signal< T_return(T_arg...)> &  signal,
T_obj &  obj,
T_return(T_obj::*)(T_arg...)  fun 
)
inline

Connect a non-const method to a signal.

Parameters
signalThe signal to connect to.
objReference to object instance the functor should operate on.
funPointer to method that should be wrapped.
Returns
A connection.
Since libsigc++ 3.8:

◆ signal_connect() [3/3]

template <typename T_return , typename... T_arg>
connection sigc::signal_connect ( signal< T_return(T_arg...)> &  signal,
T_return(*)(T_arg...)  fun 
)
inline

Connect a function to a signal.

Parameters
signalThe signal to connect to.
funThe function that should be wrapped.
Returns
A connection.
Since libsigc++ 3.8: