Re: can I pass user data to a button callback?



On Tue, 15 Feb 2005 09:32:46 -0800, Paolo Costabel
<paolo zebradevelopment com> wrote:
[...]
can I pass (a pointer to) user data to a button's callback? The compiler
wants me to create button callbacks like void (*)(void) -- but what I
need is void (*)(void*), at least for the "pressed" and "released"
signals

How could I do that?

Different GSignal's have different callback signatures; g_signal_connect
only needs the address of your callback code segment, typicly we use
the G_CALLBACK macro to cast like so:

/************** .... *****************/
void
foo_button_pressed (GtkButton *button, FooData *foo)
{

}
/************** .... *****************/
g_signal_connect (G_OBJECT (button), "pressed", 
                                 G_CALLBACK (foo_button_pressed),
(gpointer)foo);
/**************************************/

Cheers,
                                            -Tristan



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