Tomaz Canabrava wrote: > Little trouble here =) > > the g_signal_connect works like what? > g_signal_connect(GTK_WIDGET(widget), signal("clicked"), > G_CALLBACK(Function), (gpointer) "Data"); > > but the callbacks functions have the GtkWidget *Widget as a 1st > parameter, and... > well, i simply don't get it. =) > > Does anyone cares to explain to this little noob the arts and secrets > of the g_signal_connect?
void some_callback (GtkWidget *widget, MyData *data) { ... } void alternative_callback (MyData *data, GtkWidget *widget) { ... } ... MyData *data = g_malloc (sizeof (MyData)); data->foo = ...; data->bar = ...; /* Connect'em! */ g_signal_connect (widget, "some-cute-signal-name", G_CALLBACK (some_callback), data); g_signal_connect_swapped (widget, "some-cute-signal-name", G_CALLBACK (alternative_callback), data); If the signal has additional parameters, they always appear between the instance argument and user data argument, no matter what their order is (i.e. whether you use swapped/normal connection.) You can drop arguments you don't use anyway from the functions if you prefer. Of course, you can only drop a tail of the argument list, not e.g. remove the first argument and keep the second. In the example above, `data' is leaked. One common way to avoid it is to use g_signal_connect_swapped (widget, "destroy", G_CALLBACK (g_free), data); However, be aware that certain widgets can be destroyed more than once... Paul _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list