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

Re: Button destroys itself




On Tue, 10 Nov 1998, Scott. wrote:
> 
> when trying to get the cancel button to destroy the current dialog with
> the following code:
> 
> 	dialog = gtk_dialog_new();
> 	gtk_widget_show(dialog);
> 	button = gtk_button_new_with_label("Cancel");
>         gtk_widget_show(button);
>         gtk_signal_connect(GTK_OBJECT(button), "clicked",
>                            GTK_SIGNAL_FUNC(gtk_widget_destroy),
>                            GTK_OBJECT(dialog));
> 
> the cancel button itself is what gets destroyed, not the dialog (kinda
> weird)... after this statement, i proceed to fill the vbox with the other
> widgets (this is just for info)..
> 
> why is the cancel button being destroyed and not the dialog?
> 

'cuz you're confused. ;-)

The "clicked" signal (like most *but not all* Gtk signals, check the class
struct of each widget) requires a callback with this prototype: 

void callback_func(GtkWidget* widget_emitting_signal, gpointer data);

gtk_widet_destroy has this prototype:

void gtk_widget_destroy(GtkWidget* w);

So basically the button is being passed to gtk_widget_destroy (the
dialog is also passed as the second arg, but _destroy ignores it; this is
technically not allowed in C but most implementations are fine with it).

You can write your own callback, or use gtk_signal_connect_object, which
omits that first argument, so:

gtk_signal_connect_object(GTK_OBJECT(button), "clicked",
	                  GTK_SIGNAL_FUNC(gtk_widget_destroy),
                          GTK_OBJECT(dialog));

Havoc



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