I have a QWidget in a dialog. Over the course of the program running, several QCheckBox * objects are added to the layout like this:
QWidget
QCheckBox *
You can try this:
while ( QLayoutItem* item = ui->myWidget->layout()->takeAt( 0 ) ) { Q_ASSERT( ! item->layout() ); // otherwise the layout will leak delete item->widget(); delete item; }