I'm using my classes & objects which inherit QTreeWidgetItem, and it crashes when I try to do remove an item in this way:

Qt Code:
  1. ui->treeWidget->currentItem()->parent()->removeChild(ui->treeWidget->currentItem());
To copy to clipboard, switch view to plain text mode 

While this way succeeded:

Qt Code:
  1. ui->treeWidget->invisibleRootItem()->removeChild(ui->treeWidget->currentItem());
To copy to clipboard, switch view to plain text mode 

But this can only remove top level items, and it still crashed when I try to remove the last one in treeWidget. What's more, in another project QTreeWidget::clear() made it crash, too... and I don't understand the documentation of this slot.

So, why it crashed, and how to delete an item from a QTreeWidget? Thanx!