Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    2
    6163
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • O
      opengpu2 last edited by

      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

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        @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();
        }
        
        1 Reply Last reply Reply Quote 0
        • First post
          Last post