problem when I remove a widget from a container



hi,
I have a problem to destroy a widget, I create a Clist in a function:
create_func{...
GtkWidget *clist;
...
clist = gtk_clist_new_with_titles(g_list_length(Columns), Textes);
gtk_container_add(GTK_CONTAINER(main_gui.scrolled_window_games), clist);
...
}

and in another function, I'm trying to destroy this Clist after removed
it from his scrolledwindow

destroy_func{...
GtkWidget *displayed_list;
displayed_list = GTK_WIDGET(GTK_BIN(main_gui.scrolled_window_games)->child);
...
gtk_widget_hide(displayed_list);
gtk_clist_clear(GTK_CLIST(displayed_list));
gtk_container_remove(GTK_CONTAINER(main_gui.scrolled_window_games),displayed_list);
gtk_widget_destroy(displayed_list);
displayed_list = NULL;
...
}

but I obtain a warning from gtk:
Gtk-CRITICAL **: file gtkwidget.c: line 1388 (gtk_widget_destroy):
assertion `GTK_IS_WIDGET (widget)' failed.

so I tried to test if the displayed list was a widget in the destroy
function:
{...
GtkWidget *displayed_list;
displayed_list = GTK_WIDGET(GTK_BIN(main_gui.scrolled_window_games)->child);
...
gtk_widget_hide(displayed_list);
gtk_clist_clear(GTK_CLIST(displayed_list));

if (GTK_IS_WIDGET(displayed_list))
    printf("should be OK\n");
else
    printf("oups its not a widget anymore\n");

gtk_container_remove(GTK_CONTAINER(main_gui.scrolled_window_games),displayed_list);

if (GTK_IS_WIDGET(displayed_list))
    printf("should have been OK\n");
else
    printf("oups its not a widget anymore\n");

gtk_widget_destroy(displayed_list);
...
}

and I obtain this:
should be OK
oups its not a widget anymore

Gtk-CRITICAL **: file gtkwidget.c: line 1388 (gtk_widget_destroy):
assertion `GTK_IS_WIDGET (widget)' failed.

why after removing the widget from the container, it's not a widget
anymore, did I forgot something or made a mistake somewhere?
Thanks

Stéphane Pontier






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