This is strange. I understand that adding widgets via addWidget transfers ownership of the layout, so calling children() should work.
However, as an alternative, you can itemAt(int) over layout elements using count() and itemAt(int) to deliver a QLayoutItem to removeItem(QLayoutItem*) .
Edit:
I just tried addWidget with a direct C ++ test application. and it does not transfer the QObject property to the layout, so children() really an empty list. docs clearly say that property is being transferred, though ...
Edit 2:
Well, it looks like it is transferring ownership of the widget that has this layout (this is not what the docs said). This makes the elements in the layout of the layout of the layout itself in the QObject hierarchy! Therefore, it is easier to stick with count and itemAt .
source share