what is the best way to delete all QTreeWidgetItems in a QTreeWidget?



  • what is the best way to delete all QTreeWidgetItems in a QTreeWidget?
    now i use QTreeWidget::clear(), but i doubt that there is some memory not released immediately..
    thank you


  • Qt Champions 2016

    @opengpu2 said:

    QTreeWidget::clear()

    is the best way to do it.

    void QTreeWidget::clear()
    {
        Q_D(QTreeWidget);
        selectionModel()->clear();
        d->treeModel()->clear();
    }
    
    void QTreeModel::clear()
    {
        SkipSorting skipSorting(this);
        beginResetModel();
        for (int i = 0; i < rootItem->childCount(); ++i) {
            QTreeWidgetItem *item = rootItem->children.at(i);
            item->par = 0;
            item->view = 0;
            delete item;
        }
        rootItem->children.clear();
        sortPendingTimer.stop();
        endResetModel();
    }
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.