QListWidget有一个名为clear()的成员.此方法的文档状态:
void QListWidget::clear () [slot]
Removes all items and selections in the view.
Warning: All items will be permanently deleted.
Run Code Online (Sandbox Code Playgroud)
如何避免所有项目被永久删除?我只想清除列表内容,以便我可以用不同的数据重新填充它(但是,如果用户选择这样做,我想保持其中的数据再次显示).
tmp*_*rce 10
while(listwidget->count()>0)
{
listwidget->takeItem(0);//handle the item if you don't
//have a pointer to it elsewhere
}
Run Code Online (Sandbox Code Playgroud)