Vala. How do you delete all the children of a GTK container?

Viewed 8499

Solved. See the reply for examples.

I have a container with children. I need to delete all the children. This is easy in C. Vala does not work.

The following code produces an error missing type argument for collection.

var a_box = new Box (Orientation.VERTICAL, 0);
// Add some children
List children = a_box.get_children();
foreach (Widget element in children) { }

I tested over twenty variations of this code plus with many data types. When I do not get the missing type complaint, I end up with a data type that cannot be used as a widget which means I cannot destroy it.

Using Vala, not C or Python or any of the many languages where this is easy, how do you remove all the children of a container?

From what I can see, the only way to get the children is as a List but in Vala a List entry cannot be used to remove or destroy widgets.

Both remove and destroy work in C. I have several C based applications doing both. The Vala 0.30 compiler rejected every translation from C to Vala and refused to compile examples from Valadocs etc.

1 Answers
Related