Re: Passing a string to a callback function



The problem is that signal handlers are passing various parameters - not just 
the userdata, the first is usually the widget itself, the last one is usually 
the user data.

For example the 'clicked' signal for a button calls a function with a 
prototype :


void        user_function      (GtkButton *button,gpointer user_data);

(These are listed as the signals in the Gtk documentation for each widget)

so changing your callbackfunc to :


	void callbackfunc(GtkButton *button_that_was_clicked, gchar *string) {
		printf("%s\n",string);
	}

will probably work...



There is also the g_signal_connect_swapped.

If you use this instead of g_signal_connect it will 'swap' the widget and the 
userdata in any callback it calls, so in the above case, the callback would 
be:


void        user_function      (gpointer user_data,GtkButton *button);


This means that your current callback function will work as the first 
parameter is the userdata not the widget


HTH...



On Thursday 05 February 2004 12:02 pm, Ricardo Cervera wrote:
> Hi.
>
> I am having problems trying to pass a string to a callback
> function via g_signal_connect. Isn't that possible?
>
> For example, in main I have something like
>
> g_signal_connect(widget, "whateversignal", G_CALLBACK(callbackfunc),
>                         (gchar *)"string I want to pass");
>
> My callaback function could be
>
> void callbackfunc(gchar *string)
> {
> 	printf("%s\n", string);
> }
>
> But it doesnt print the string I pass to it, it prints something strange
> instead. What am I doing wrong?
>
>
> Thanks.
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list




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