[Qt-interest] Problem deleting QTreeWidgetItem objects

Bruno Tomazela btomazela1 at gmail.com
Thu Apr 2 19:06:25 CEST 2009


Hi everybody,

I'm facing a strange problem with QTreeWidget and QTreeWidgetItem.
I'm inserting and removing QTreeWidgetItem items in a QTreeWidget
consecutively and the memory usage explodes.

I set up a GUI app with just an empty QTreeWidget to test the memory
behavior when deleting items (QTreeWidgetItem).
So, when I execute the following code on this test app:

 void MainWindow::testTreeWidget(){

 for (int i = 0; i < 100000; i++){


if (i % 10000 == 0) QTest::qWait(1); //<-- WAIT CONDITION

this->createItem();

 this->deleteItem();

 }

}


 void MainWindow::createItem(){

 this->treeWidget->insertTopLevelItem(0, new
QTreeWidgetItem((QTreeWidget*)0));

}


 void MainWindow::deleteItem(){

 QTreeWidgetItem

*deletedItem;


deletedItem = this->treeWidget->invisibleRootItem()->takeChild(0);


delete deletedItem;

}


and compile without the WAIT CONDITION line, the memory usage grows up to
30MB.
But when I compile with the WAT CONDITION line, the memory usage doesn't go
over 5.2MB.

Am I missing something here or delete isn't working properly?

Thanks in advance,
Tomazela.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090402/e1b329f0/attachment.html 


More information about the Qt-interest-old mailing list