If I delete a QWidget
using delete
, does it unregister itself from the GUI or do I have to do this manually? Is there a logical reason for this behavio
As already pointed out by @CatPlusPlus , Qt uses an ownership system. So whenver you add widgets to layouts or layouts to widgets and so forth the ownership of the addee is given to the adder/parent. This is usually documented in the method documentation. For example if you look at documentation for QWidget::addLayout(QLayout*), it says the Qwidget takes ownership of the QLayout. When you delete the parent it deletes all its children as well. Read this article for more info .
Object Trees and Ownership in Qt
This method is very useful, because in traditional C++ the developer has to keep track of every bit of memory allocated on the heap. This ownership system however requires that the developer onl keep track of the parents.