Re: user data in signals
- From: Daniel Elstner <daniel kitta googlemail com>
- To: Christopher Harvey <chris basementcode com>
- Cc: gtkmm-list gnome org
- Subject: Re: user data in signals
- Date: Mon, 15 Jun 2009 01:53:35 +0200
Am Sonntag, den 14.06.2009, 19:14 -0400 schrieb Christopher Harvey:
> I've got a button signal handler, so it takes no parameters. I was
> wondering if there was some way I could send "user data" when the signal
> is connected.
Sure.
> something like this:
>
> void handlePress(int buttonID) {
> //I use buttonID here
> }
>
> int main() {
> b1.signal_clicked().connect(ptr_fun(handlePress(1)));
> b2.signal_clicked().connect(ptr_fun(handlePress(2)));
> b3.signal_clicked().connect(ptr_fun(handlePress(3)));
> }
Make that:
b1.signal_clicked().connect(sigc::bind(&handlePress, 1)));
b2.signal_clicked().connect(sigc::bind(&handlePress, 2)));
b3.signal_clicked().connect(sigc::bind(&handlePress, 3)));
> Doesn't plain gtk support something like this?
Yes it does. In fact, language bindings in particular make extensive
use of this important feature of the G* APIs. :-)
gtkmm maps GObject signals to sigc++, which is much more powerful and
compile-time type-safe.
--Daniel
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]