Hi Junior,
I don't get why we have to call "delete".
well, anyways, I got a brand new fresh problem. I gave up on just deleting it, I want to return it. here goes my function:
/* Removes the current item from the TreeWidget, and returns it */ QTreeWidgetItem *Editor::removeItemTree() {
QTreeWidgetItem *currentParent = ui.treeWidget->currentItem()->parent();
QTreeWidgetItem *currentItem = ui.treeWidget->currentItem();
/* if the current item has a parent (it's not a TopLevelItem) */
if (currentParent)
return currentParent->takeChild(currentParent->indexOfChild(currentItem));
/* if the current item does not have a parent (it IS a TopLevelItem) */
else
{
rootItem = ui.treeWidget->invisibleRootItem();
return rootItem->takeChild(rootItem->indexOfChild(currentItem));
}
}
this doesn't work either.
I tried your piece of code, and it didn't work, that must be because we have some thing different on our codes. I'll check it throughoutly.
but what amazes me is that ui.treeWidget->clear(); DOES NOT WORK! how the heck?
PS: oh, now I know why...:
from QTreeWidget API:
"Note: Since each item is removed from the tree widget before being deleted, the return value of
QTreeWidgetItem::treeWidget() will be invalid when called from an item's destructor."
it tries to remove the last item... and fails miserably too... dang, what to do...?