[SOLVED]Little question about memory when delete
-
Hello,
I'm currently using a window which has a layout principal. It's contains loads of object such as QPushButtons, QLabel...
In my destructor, I destroy the layout and all the widgets.
Ad the layout countains all the widget, I was wondering if doing just "delete layout" would be enough to get a clean memory.Thanks
-
And the widget included in a layout are also considered as children of the layout?
-
Hi,
one clearification:
The layout has no widgets as children. The layout is some organizational stuff, that is attached as child to a widget. The widgets inside a layout are chidlren of the parent of the layout.Deleting the main window containing the top layout is enough to delete all children (widgets, layouts and other QObject derived classes)
-
http://doc.qt.nokia.com/latest/layout.html
Look at "Tips for Using Layouts" section.
EDIT:
Tips for Using LayoutsWhen you use a layout, you do not need to pass a parent when constructing the child widgets. The layout will automatically reparent the widgets (using QWidget::setParent()) so that they are children of the widget on which the layout is installed.
Note: Widgets in a layout are children of the widget on which the layout is installed, not of the layout itself. Widgets can only have other widgets as parent, not layouts.
You can nest layouts using addLayout() on a layout; the inner layout then becomes a child of the layout it is inserted into.
-
Okay,
It's not so simple tho, I really have to check each widget if they are only parented to the layout and not another widget, if I followed what you all said.
Thanks for all the answers.