I am studying the issue of competent memory management. As I understand it, it is not necessary to call the delete() method for each widget, it is enough to declare it parent when creating it and all parent widgets will be deleted when the parent is deleted.
Now, there is a QMdiSubWindow window. Window creation code:
CatProducts *catProducts = new CatProducts(); catProducts->setObjectName("catProducts"); mdiArea->addSubWindow(catProducts); catProducts->show(); The Qt::WA_DeleteOnClose attribute is assigned to the Qt::WA_DeleteOnClose . On this window, I hang QWidget as an internal widget , and on it the rest of the widgets. Code like this:
QWidget *internalWidget = new QWidget(this); setWidget(internalWidget); QGridLayout *layout = new QGridLayout(internalWidget); internalWidget->setLayout(layout); QTreeView *tree = new QTreeView; tree->setFixedWidth(100); layout->addWidget(tree,1, 1, 1, 3); QPushButton *button = new QPushButton("BUTTON"); layout->addWidget(button, 2, 1); Now the task manager in Windows is testing the memory consumption by opening / closing my QMdiSubWindow . When opening, the volume of consumed memory increases, and when closed, it does not decrease. Those. occupied memory is not released. How to do it right?
And another question: on the example of layout , but passing it as a parameter to the constructor of QTreeView *tree = new QTreeView(layout) and the layout->addWidget(tree) entry are identical? Those. in both cases, is the layout the parent widget for the tree ?
#ifdef _debugand#endifmake it easier to remove. - nick_n_a