There's a count
method that returns the number of stored widgets, and a itemAt()
method that, given an index, it returns the pointer to relative stored widget. You can retrieve all pointers and then remove them. You should first retrieve all pointers, because if you remove one while counting then the number of stored widgets changes during iterations.
itemAt()
retrieve a QLayoutItem
with a widget
method that retrieves the widget itself.
while (layout->count() != 0) {
QLayoutItem *item = layout->itemAt(0);
layout->removeWidget(item->widget());
}