I believe that you are doing almost the same thing, although not one of them will correctly remove from the layout how you should do it. They still remain bad links in the layout (if I remember correctly)
The first item simply deletes the item. The second will delete it as soon as the control returns to the event loop. But in fact, the way people usually remove elements from the layout is to take them from the layout (giving it the opportunity to customize it), and then remove the element and its widget (if you want).
QLayoutItem *child; while ((child = layout->takeAt(0)) != 0) { delete child->widget(); delete child; }
Again, removing the widget ( child->widget() ) is only necessary if you want to destroy the added widget in addition to the layout element that held it.
source share