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. Updating records using QSqlTableModel
Qt 6.11 is out! See what's new in the release blog

Updating records using QSqlTableModel

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.3k 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.
  • A Offline
    A Offline
    Abdurahman_Gulamkadirov
    wrote on last edited by
    #1

    Hi there!

    I'm working with MySql. I have got a table called product, and it has some fields(name, producer, barcode, cost, amount). I should insert data from GUI, so I'm using QTableView and QSqlTableModel:

    QSqlTableModel *model = new QSqlTableModel(this, database);//database - QDataBase, and is open
    model->setTable(product);//for inserting, I don't need all data in product, so I don't select()
    model->setEditStrategy(QSqlTableModel::EditStrategy::OnManualSubmit);
    ui->tableView->setModel(model);
    

    And there's a button calles Submit. Whet it is pressed, the data should be updated if it is exists in product table, otherwise it should be inserted. If name column of a row in the table is in product, it's amount should be incremented to value in the row. But I have no idea how to do this, could you plz help?

    JonBJ 1 Reply Last reply
    0
    • A Abdurahman_Gulamkadirov

      Hi there!

      I'm working with MySql. I have got a table called product, and it has some fields(name, producer, barcode, cost, amount). I should insert data from GUI, so I'm using QTableView and QSqlTableModel:

      QSqlTableModel *model = new QSqlTableModel(this, database);//database - QDataBase, and is open
      model->setTable(product);//for inserting, I don't need all data in product, so I don't select()
      model->setEditStrategy(QSqlTableModel::EditStrategy::OnManualSubmit);
      ui->tableView->setModel(model);
      

      And there's a button calles Submit. Whet it is pressed, the data should be updated if it is exists in product table, otherwise it should be inserted. If name column of a row in the table is in product, it's amount should be incremented to value in the row. But I have no idea how to do this, could you plz help?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Abdurahman_Gulamkadirov
      This is all standard/straightforward. You should have read
      https://doc.qt.io/qt-5/sql-model.html#the-sql-table-model
      https://doc.qt.io/qt-5/qsqltablemodel.html#details

      and some example like, say
      https://programmer.group/sql-table-model-qsqltable-model.html

      A 1 Reply Last reply
      2
      • JonBJ JonB

        @Abdurahman_Gulamkadirov
        This is all standard/straightforward. You should have read
        https://doc.qt.io/qt-5/sql-model.html#the-sql-table-model
        https://doc.qt.io/qt-5/qsqltablemodel.html#details

        and some example like, say
        https://programmer.group/sql-table-model-qsqltable-model.html

        A Offline
        A Offline
        Abdurahman_Gulamkadirov
        wrote on last edited by Abdurahman_Gulamkadirov
        #3
        This post is deleted!
        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