Reputation: 638
I have a vcontainer which is populated with a gtk_combo_box and several buttons i would like to clear the buttons only from within the vcontainer, I tried the following code:
GList *vcontainer_children, *iter;
vcontainer_children = gtk_container_get_children(GTK_CONTAINER(container));
for(iter = vcontainer_children; iter != NULL; iter = g_list_next(iter))
{
if (gtk_button_get_label(iter));
gtk_widget_destroy(GTK_WIDGET(iter->data));
}
the code clears all widgets in the vcontainer, one possibility would be to replace the if with a function that checks whether iter is a button or not, but I do not know how that is done
Upvotes: 0
Views: 34
Reputation: 11588
if (gtk_button_get_label(iter));
The semicolon at the end is wrong; this is the same as saying
if (gtk_button_get_label(iter))
/* do nothing */;
and as such the gtk_widget_destroy()
always runs.
Simply remove the semicolon or switch to using braces for everything (or some other option I didn't think of).
Your condition is also wrong for two reasons. First, it uses iter
instead of iter->data
. Second, it will crash and burn spectacularly if the widget isn't a button. Fortunately there's a macro GTK_IS_BUTTON()
you can use instead:
if (GTK_IS_BUTTON(iter->data))
gtk_widget_destroy(GTK_WIDGET(iter->data));
Upvotes: 1