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. How to update the selected row in QTableview using a button
Forum Updated to NodeBB v4.3 + New Features

How to update the selected row in QTableview using a button

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.9k 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.
  • lmofallisL Offline
    lmofallisL Offline
    lmofallis
    wrote on last edited by lmofallis
    #1

    Hi,

    I am using a QSqlTableModel for a SQLite database.
    The SQLite database contains a:

    • Table: "ThePer"
    • Columns: ID, Name, Work.

    Also, I have a Tableview to display the database's content, and a button to update the content of the selected row.
    When I click the button to update the 'Work' column of the selected row, thats work only the first time. And doesn't work when I want to update an other selected row.

    This is my short code:

        QModelIndex TheIndex = ui->tableView->selectionModel()->currentIndex();
        TheModel->setEditStrategy(QSqlTableModel::OnFieldChange);
        TheModel->setData(TheModel->index(TheIndex.row(),2), true, Qt::EditRole);
        TheModel->select();
        // TheModel->submitAll();
        TheDB.close();
    

    Thanks.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      You r working with current index. How r u changing current index ? That may b the issue.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      lmofallisL 1 Reply Last reply
      1
      • dheerendraD dheerendra

        You r working with current index. How r u changing current index ? That may b the issue.

        lmofallisL Offline
        lmofallisL Offline
        lmofallis
        wrote on last edited by lmofallis
        #3

        @dheerendra
        what I know is that the current index changes when I select an other row.
        I can upload my code in "mega.nz", but I don't know if it's allowed here.

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          If ur selecting next row it should work. U can upload the code there. Will check it.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          lmofallisL 1 Reply Last reply
          1
          • dheerendraD dheerendra

            If ur selecting next row it should work. U can upload the code there. Will check it.

            lmofallisL Offline
            lmofallisL Offline
            lmofallis
            wrote on last edited by
            #5

            @dheerendra
            I'm sorry for my late reply. But, I replaced this with a new strategy.
            Thank you any way.

            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