8

QListWidget 有一个名为 clear() 的成员。此方法的文档状态:

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

如何避免所有项目被永久删除?我只想清除列表内容,以便我可以用不同的数据重新填充它(但是,如果用户选择这样做,我想保留其中的数据以再次显示)。

4

1 回答 1

11

QListWidget::takeItem

while(listwidget->count()>0)
{
  listwidget->takeItem(0);//handle the item if you don't 
                          //have a pointer to it elsewhere
}
于 2012-03-07T02:04:37.453 回答