Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. what is the best way to delete all QTreeWidgetItems in a QTreeWidget?

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 7.8k Views
  • 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 Offline
    O Offline
    opengpu2
    wrote on last edited by
    #1

    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
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved