I know there is many questions about memory management in Qt. Also I read these SO questions:
But in my case, I confused again!
I have a QTableWidget
with name myTable
. I add run-time widgets to it by setCellWidget
:
void MyClass::build()
{
for (int i=LOW; i<HIGH; i++)
{
QWidget *widget = new QWidget(myTable);
//
// ...
//
myTable->setCellWidget(i, 0, widget);
}
}
Then, I delete all items like below:
void MyClass::destroy()
{
for (int i = myTable->rowCount(); i >= 0; --i)
myTable->removeRow(i);
}
These methods call many times during long time. And myTable
as the parent of those widgets will live along program's life-time.
Dose method destroy()
release memory quite and automatically? Or I have to delete
allocated widgets myself like below?
void MyClass::destroy2() // This maybe causes to crash !!
{
for (int i = myTable->rowCount(); i >= 0; --i)
{
QWidget *w = myTable->cellWidget(i, 0);
delete w;
myTable->removeRow(i);
}
}