[sigc] Re: Signals & Slots



> I think if you just follow through the different typical tasks you might
> undertake with the two libraries as Murray wrote:

For libsigc++ 2, this is:

> 1. Create a signal

//Create a signal whose handler would look like this:
//int SomeClass::on_signal(A a, B b);
sigc::signal<int, a, b> signal_example;

> 2. Connect a slot (callback function) to a signal.
>   2.2 For a member method.

//If this is an instance of SomeClass.
signal_example.connect( sigc::mem_fun(*this, &SomeClass::on_signal) );

>   2.3 For a non-member or static function.

signal_example.connect( sigc::ptr_fun(on_signal_static_function) );

> 3. Disconnect a slot.

//If I save the connection, like so:
sigc::connection con = signal_example.connect( sigc::mem_fun(*this,
&SomeClass::on_signal) );

//then I can do:
signal_example.disconnect(con);

> 4. Bind an extra parameter, so that e.g. a slot with 4 parameters can be
> used with a signal with 3 parameters. I don't personally find the more
> complex adaptors interesting.

//If we have a signal handler that look like this:
//int SomeClass::on_signal(A a, B b, int c);
//but the signal was declared as
//sigc::signal<int, a, b> signal_example;
//then we can do:

signal_example.connect( sigc::bind( sigc::mem_fun(*this,
&SomeClass::on_signal), 1 /* the value for c */ );


Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]