How can I empty a QListWidget without having it delete all of the QListItemWidgets it contains?

StackOverflow https://stackoverflow.com//questions/9594768

  •  08-12-2019
  •  | 
  •  

Question

QListWidget has a member named clear(). The docs for this method state:

void QListWidget::clear () [slot]
Removes all items and selections in the view.
Warning: All items will be permanently deleted.

How can I avoid all of the items being permanently deleted? I just want to clear the lists contents so that I can re-populate it with different data (however, I want to keep the data that was in it to display again if the user chooses to do so).

Était-ce utile?

La solution

QListWidget::takeItem

while(listwidget->count()>0)
{
  listwidget->takeItem(0);//handle the item if you don't 
                          //have a pointer to it elsewhere
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top