[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!



  • guess no answer means difficult problem


  • Moderators

    I had a look to your post this morning. However, it is difficult to understand what you are doing.
    My recommendation would be to give some more explanations especially such as classes you are using. This might people give a chance to help.



  • 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


  • Moderators

    Thanks for sharing your solution.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.