[solved]delete row not deleting :(
-
I have the next code:
@void ExportData::on_quitar_clicked()
{
this->rows_selected = this->ui->table_agregados->selectionModel ()->selectedRows ();
foreach (QModelIndex index, rows_selected){
this->ui->table_agregados->removeRow (index.row ());
}
}
@everything works fine if i select only one row, but if i have multiple rows selected, the last one is not deleted...why is that happening? how would you solve it?
thanks!
-
hi thanks for your answer! the problem was that the code posted only deletes half of the rows selected because when one row is deleted the row#number of the remaining rows is reorganized..so the right thing to do would be:
@void ExportData::on_quitar_clicked()
{
QModelIndexList selected = ui->table_agregados->selectionModel()->selectedRows();
for(int i=selected.count()-1;i>=0;i--) {
ui->table_agregados->removeRow(selected.at(i).row());
}
}@that way everything is deleted :D