Re: variables in g_signal_connect



You should use the GINT_TO_POINTER() macro on your variable. Then use
GPOINTER_TO_INT() to extract the int back out of the pointer.

 See this: http://developer.gnome.org/doc/API/2.0/glib/glib-Type-Conversion-Macros.html#GINT-TO-POINTER:CAPS

This method will work, but only for integers (since pointers are
really just integers that store a memory address). If you want to pass
other variable types (or even multiple variables), just create a
struct with everything you need, make a pointer that points to it, and
pass that to your signal handler.

Cheers,
Chris Anderson


On 7/14/05, Michal Porzuczek <mporzuczek gmail com> wrote:
When connecting signals to methods is is possible to add additional
variables to the signals and if so in which way. Furthermore, the 4th
variable, data, does it have to be a gpointer?

I have the following function defined as:

Horizontal_Zoom_In_clicked(GtkWidget *widget, int gt)

and the signal connection as:

g_signal_connect ((gpointer) Horizontal_Zoom_In, "clicked",
                                  G_CALLBACK (Horizontal_Zoom_In_clicked),
                                  graph_type);

where graph_type is an int. as a result I get a
warning: passing argument 4 of 'g_signal_connect_data' makes pointer
from integer without a cast

now I was wondering if it is possible to pass a variable into the
Horizontal_Zoom_In_clicked method without it being a gpointer but an
int instead and if so how this is to be done.

Thanks a lot,

Michal
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




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