Re: signals with parameters



Andreas Volz wrote:

Hi,

I've a window class which creates some HScale widgets based on a
saved file. So I create them dynamic with new and store the pointers in
a std::vector. This works great, but I could only connect all HScale
widgets to one callback function:

     hscale->signal_value_changed ().connect (sigc::mem_fun (*this,
         &Application::on_target_hscale_changed));

In this callback I like to get the correct HScale widget pointer whose
value was changed. I found this in docs:

http://libsigc.sourceforge.net/libsigc2/docs/manual/html/ch02s03.html

This reads like the stuff I need, but how could I use this with HScale?
Need I to derivate HScale and add this new signal with parameters? How
how could I do this?

regards
Andreas
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list

Hi Andreas,

use sigc::bind to do this:

First prototype Application::on_target_hscale_changed with a gint as its formal calling parameter. then make your signal connection call look like the following:

hscale->signal_value_changed().connect(sigc::bind<gint>(sigc::mem_fun(*this,&Application::on_target_hscale_changed),i));

where "i" is the zero based index of your derived hscale object in your std::vector. Now, when Application::on_target_hscale_changed is called when signal_value_changed is emitted, it will be supplied with the value of "i" as its formal parameter thereby letting you know which hscale emitted the signal.

Cheers,
Bob Caryl



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