I was trying to remove all selected indices of a QTableView,
Now I use:
foreach (const QModelIndex & idx, model->selectionModel()->selectedIndexes())
{
model->removeRow (idx.row()); // Obviously bug
}
There's a obvious problem that once you remove the row, the row id is invalidated, w
As there's no function that takes directly the index (or does the index act like a iterator that will get invalidated when data changed?), I don't know what to do.
There is QPersistanceModelIndex
class which keeps valid state of index. I tried and it seems to be working.
QList<QPersistentModelIndex> indexes;
foreach (const QModelIndex &i, ui->tableView->selectionModel()->selectedIndexes())
indexes << i;
foreach (const QPersistentModelIndex &i, indexes)
ui->tableView->model()->removeRow(i.row());
I hope it will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With