Search code examples
c++qtmemoryqtreewidgetitem

qt 4.7 removeChild() and memory


Im writing a c++ qt application. In one part I'm creating a QTreeWidget. The user has all possibilities to create and delete entries in that tree. So when the user creates a item he will call a function which then itself calls:

QTreeWidgetItem* newItem = new QTreeWidgetItem();

When the user later decides to delete the entry, he calls a function which then itself will call:

QTreeWidgetItem* curItem = _ui->qTreeWidget->currentItem();
QTreeWidgetItem* parent = curItem->parent();
parent->removeChild(curItem);

The question that erases for me is now: what about the memory this item occupied? What The Qt 4.7 doc says to removeChild is the following:

void QTreeWidgetItem::removeChild ( QTreeWidgetItem * child ) Removes the given item indicated by child. The removed item will not be deleted.

So how do i delete a child?

Thanks a lot in advance! Donny


Solution

  • How about

    delete curItem;
    

    ?

    According to the documentation, the destructor will remove the item from the tree in which it is included, so I think you don't even need to perform the removeChild beforehand.