How do I delete a top level QTreeWidgetItem from a QTreeWidget?

deleteing a QTreeWidgetItem directly is perfectly safe.

According to the documentation for ~QTreeWidgetItem():

Destroys this tree widget item. The item will be removed from QTreeWidgets to which it has been added. This makes it safe to delete an item at any time.

I've used delete on many QTreeWidgetItems in practice and it works quite well.


To delete a top level item call QTreeWidget::takeTopLevelItem method and then delete the returned item:

delete treeWidget->takeTopLevelItem(index);

Where index is index of the item to be removed.