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. Update QTableView after remove a row
Forum Updated to NodeBB v4.3 + New Features

Update QTableView after remove a row

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 4.4k Views 3 Watching
  • 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.
  • AmrCoderA Offline
    AmrCoderA Offline
    AmrCoder
    wrote on last edited by AmrCoder
    #1

    I have some Rows in a QTableView I add them using QSqlTableModel
    now I use this code to remove the selected row

        int r = ui->tableView->selectionModel()->currentIndex().row();
        ui->tableView->model()->removeRow(r);
    

    but nothing happend i want to update the view how can i do that as when i use this code the row still found but when i press Save button it edit my database table and remove it but not from the view.
    Thanks in advance.

    A 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What if you call select on the model afterward ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • AmrCoderA Offline
        AmrCoderA Offline
        AmrCoder
        wrote on last edited by
        #3

        i add the select to the model after the remove but nothing happend

            int r = ui->tableView->selectionModel()->currentIndex().row();
            ui->tableView->model()->removeRow(r);
            model->select();
        

        the row still found but it take no number it not count when i select a row and press remove button which have the above function it make a question mark beside this row and remove it's number between the rows
        when i press the save button which contains this code

            if(model->submitAll())
                model->database().commit();
            else
                model->database().rollback();
            QMessageBox::information(this, "Done", "Data saved!");
        

        it starts to take the effect and remove the row from the tableview i asked how to remove it without press the save button and let it show in the tableview if this possible.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Sorry, I forgot about the submission part. If you don't want to have to press that other button, then you have to submit your change in the function that removes the row.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • S Offline
            S Offline
            sadeq
            wrote on last edited by
            #5

            I use QSqlTableModel::OnFieldChange Edit strategy and then model->select(); and it works fine
            if I use OnManualSubmit Edit strategy the same things happens and I think it's in the model's design and not a BUG, so I guess if you need to change that behavior you have to subclass.

            1 Reply Last reply
            1
            • AmrCoderA AmrCoder

              I have some Rows in a QTableView I add them using QSqlTableModel
              now I use this code to remove the selected row

                  int r = ui->tableView->selectionModel()->currentIndex().row();
                  ui->tableView->model()->removeRow(r);
              

              but nothing happend i want to update the view how can i do that as when i use this code the row still found but when i press Save button it edit my database table and remove it but not from the view.
              Thanks in advance.

              A Offline
              A Offline
              ambershark
              wrote on last edited by
              #6

              @AmrCoder https://forum.qt.io/topic/89942/sql-table-view-removed-element-stays-on-the-view

              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

              1 Reply Last reply
              2

              • Login

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