Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]delete row not deleting :(

[solved]delete row not deleting :(

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KillGabio
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KillGabio
      wrote on last edited by
      #2

      guess no answer means difficult problem

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #3

        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.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • K Offline
          K Offline
          KillGabio
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • K Offline
            K Offline
            koahnig
            wrote on last edited by
            #5

            Thanks for sharing your solution.

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved