Re: [gtk-list] Why doesn't it work ??

Thank you David for your response to my question.

I had a second look at the 'gtk+-devel-1.2.5' and the 'GTK+ Reference
Manual'.  I am not sure why I though that a callback had to have the
void callback_func (GtkWidget *widget, GdkEvent *event, gpointer

Instead of the correct (to spec):
void callback_func( GtkWidget *widget, gpointer   callback_data );

Thank you.

I was hopeful that this might be the source of my problems with
callbacks, but leider this did not seem to solve my problem when I made
the appropriate changes to my sample program.

I attach the program again, with the changes to the callback from.  But
the problem persists.  I noticed that I did not actually state the
nature of my problem last time so:

As I noted I want to change the label of a toggle button dependent on
the state of the button.  using the call:
void gtk_label_set_text( GtkLabel *label, char     *str );
This call works, if tested in the main func. of the program toggle.c,
but if put into a callback 'cb_toggle' the program receives a
"segmentation fault" when the toggle button is toggled, i.e. in the
callback which contains only the call to gtk_label_set_text.  Using
xxgdb I have noticed that the pointer 'label' dose not maintain its
value once viewed in the callback.  If the GtkWidget *label is set as a
global variable then the program works (or using the 'set variable val',
feature of xxgdb to reset the variable to its value in the main func.).
But using global variables is not my idea of a solution.  The other
problems I am having with callbacks all relate to pointer dereferencing
when passed to the callback.

I appreciate your help.
#include <gtk/gtk.h>

void cb_toggle (GtkWidget*, GtkWidget*);
void cb_exit (GtkWidget*, gpointer);
int main (int, char**);

void cb_toggle (widget, label)
GtkWidget *widget;
GtkWidget *label;
	gtk_label_set_text (GTK_LABEL (label), "DOWN");

void cb_exit (widget, data)
GtkWidget *widget;
gpointer data;
	gtk_main_quit ();

int main (num, str)
int num;
char **str;
	GtkWidget *window;
	GtkWidget *toggle;
	GtkWidget *label;

	gtk_init (&num, &str);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_signal_connect (GTK_OBJECT (window), "delete_event",
		GTK_SIGNAL_FUNC (cb_exit), NULL);

	toggle = gtk_toggle_button_new ();
	gtk_container_add (GTK_CONTAINER (window), toggle);
	gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
		GTK_SIGNAL_FUNC (cb_toggle), label);
	gtk_widget_show (toggle);

	label = gtk_label_new ("UP");
	gtk_container_add (GTK_CONTAINER (toggle), label);
	gtk_widget_show (label);

	gtk_widget_show (window);

	gtk_main ();

	return (0);


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