Re: unref-erencing a GtkWindow



Emmanuel Briot <briot act-europe fr> writes:

> James Henstridge <james daa com au> writes:
> 
> > You don't own the reference to the GtkWindow, so calling g_object_unref()  (or
> > whatever) on it is an error.
> 
> Should we get a segmentation fault when one calls g_object_unref() on a
> GtkWindow ? It would be nice if it could be protected.

Yep, you should get a segmentation fault. You can *never* call
g_object_unref() on an object that you don't own a reference
for. You never own a reference on a newly created GtkWidget (*)
 
> How, then, can I own a reference to the gtk window ? In my case, this is a
> GtkWindow that the user has put in my MDI container, and that the container is
> now responsible for. However, I'd like the user to be able to specify that the
> window should not be destroyed, just removed from the MDI control when the "X"
> button in the title bar is pressed.

You can own a reference to the gtk window by calling g_object_ref().

Regards,
                                        Owen

(*) The initial reference on a newly created GtkWidget is generally
    not owned by anyone. The way you "claim ownership" of this
    reference is:

     g_object_ref (object);
     gtk_object_sink (object);

    GtkWindow is an exception - it owns its own initial reference.
    For a GtkWindow, gtk_object_sink (window) is a no-op,
    so the above sequence works as well.



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