Calling QTreeWidgetItem::takeChildren() on invisibleRootItem() results
in a crash because it calls QTreeModel::beginRemoveItems() which calls
QTreeModel::index() on that item which returns an invalid QModelIndex.
Instead iterate over topLevelItem's and sort them.