void MainWindow::deleteAllSlot()
{
int counter =ui->listWidget->count();
for(int index=0;index<counter;index++)
{
QListWidgetItem *item = ui->listWidget->takeItem(0);
delete item;
}
}
是需要吧takeItem(0);而不是takeItem(index);就可以了;此外需要配置好槽和.h文件以及按钮等;
QObject::connect(ui->deleteAllBtn,SIGNAL(clicked()),this,SLOT(deleteAllSlot()));