problem removing selected rows from QTableWidget
I want to remove selected rows from QTableWidget..When i click on the button,if i have,for example three selected items only 2 are deleted.
Why this occurs?
This is my code:
QList <QTableWidgetItem *> items = ui->tableWidget->selectedItems();
for (int x=0;x<ui->tableWidget->rowCount();x++)
{
if(items.at(x)->isSelected())
ui->tableWidget->removeRow(x);
}
Re: problem removing selected rows from QTableWidget
The first time you remove a row subsequent row numbers change. For example, remove row 2 and row 3 becomes the new row 2, you then increment x and look at row 3. The original row 3 never gets looked at.