Layouts do not contain widgets.
They contain layout items.
So, if you want to delete the widgets, first browse through the list of items, delete the widget or child layout in the item, then remove the item itself.
In pseudo code:
while layout has items
layoutitem i = layout.takeat(0) //takes the first item
if (i.widget())
delete i.widget();
if (i.layout())
delete i.layout();
delete i;
loop
while layout has items
layoutitem i = layout.takeat(0) //takes the first item
if (i.widget())
delete i.widget();
if (i.layout())
delete i.layout();
delete i;
loop
To copy to clipboard, switch view to plain text mode
Bookmarks