[Glade-users] Closing a dialog window



On Sun, 2005-01-30 at 14:06 +0000, Chris Morrison wrote:
On Sat, 2005-01-29 at 20:52 +0000, Keith Sharp wrote:
On Sat, 2005-01-29 at 12:34 +0000, Chris Morrison wrote:

I have placed the following code in the signal handler for the Close
button's click event.

void on_closebutton_clicked(GtkButton *button, gpointer window_ptr)
{
  GtkDialog *window = GTK_DIALOG(window_ptr);
  gtk_widget_destroy(GTK_WIDGET(window));
}

However, when I click on the Close button nothing happens and the
following message is displayed in the terminal window.

(my-program:5534): Gtk-CRITICAL **: file gtkwidget.c: line 1911
(gtk_widget_destroy): assertion `GTK_IS_WIDGET (widget)' failed

1) How are you connecting the callback, which you show above, to the
object and the signal?  I assume you have a call to g_signal_connect
somewhere in your code.  Can you show us some more of your code?

g_signal_connect ((gpointer) closebutton, "clicked", G_CALLBACK
(on_closebutton_clicked), NULL);

The last parameter of this function is for extra data you want to pass
to the callback, in your case this would the pointer to your window.
You need to change this code to somethings like:

GtkDialog *dialog;

/* Create and setup dialog here */

g_signal_connect (closebutton, "clicked", G_CALLBACK (on_closebutton_clicked), window);

This should now allow your callback to work as you expect.

This was pasted from the interface.c file.

Using autogenerated code from GLADE is considered bad practise.  Can I
suggest you take a look at the GTK+ Tutorial:

                http://www.gtk.org/tutorial/

which should give you a better understanding of how things work.

Keith.





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