On 20 July 2012 07:50, Frank Cox <thea...@melvilletheatre.com> wrote:
> How can I check if a GtkWidget exists?
>
> I am planning to create and destroy widgets in a window depending on the 
> user's
> selections, but I can't figure out how to determine if a particular widget
> already exists in the window so it won't be created twice or receive a
> second deletion attempt if it's already gone.
>
> I tried checking GTK_WIDGET_REALIZED but it appears that if the widget has
> previously been destroyed then the GTK_WIDGET_REALIZED tries to access it
> anyway and gives me an error.
>
> Is there a way to determine if a widget is already in a window without having
> to maintain my own table?

I would just accept it is not possible and create my own data struct
containing a GtkWidget* for each widget type I want to create.
Initialize them to zero and only allow creation of a certain widget
type if the appropriate pointer is zero, and conversely, only allow
deletion if the pointer is non-zero. Ensure to set the pointer to zero
after deleting the widget.

g_object_ref and g_object_unref also spring to mind, but I'm fairly
sure this is not the type of scenario where you'd use them and will
probably only cause confusion.

James.
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to