Re: unref-erencing a GtkWindow



Emmanuel Briot wrote:

Hello all,

While writting an MDI widget with GtkAda, in which, among other features, the
user can insert any kind of widget, including a toplevel GtkWindow), I
encountered the following problem:

It seems that one can not do a gtk_widget_unref() on a GtkWindow.
The following program results in a segmentation fault.

#include <gtk/gtk.h>

int main (int argc, char** argv) {
 GtkWidget* win;
gtk_init (&argc, &argv);
 win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 gtk_widget_show_all (win);

 gtk_widget_unref (win);
 //    gtk_widget_destroy (win);

 gtk_main ();
}



Whereas if you replace the gtk_widget_unref() by the call to
gtk_widget_destroy(), the main loop is properly started.

Is this expected ?


What I am trying to achieve is that if the user as gtk_widget_ref()-ed the
widget before putting it in the MDI, then this widget is never destroyed, even
when removed from the MDI. This can be used for instance to always reuse the
same instance of the widget when the user wants to open a search dialog in an
IDE.
Therefore, I believe I shouldn't call gtk_widget_destroy() explicitely. Am I right ?

Any suggestion would be most welcome.

thanks in advance
You don't own the reference to the GtkWindow, so calling g_object_unref() (or whatever) on it is an error. However, calling gtk_object_destroy() on a GtkWindow is not an error (it is the correct way to destroy a toplevel window and all its children). The GtkWindow is then responsible for destroying its children.

James.

--
Email: james daa com au              | Linux.conf.au 2003 Call for Papers out
WWW:   http://www.daa.com.au/~james/ |   http://conf.linux.org.au/cfp.html







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