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. QSqlTableModel: Updating record
Forum Updated to NodeBB v4.3 + New Features

QSqlTableModel: Updating record

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

    What is the cleanest way to update in QSqlTableModel? I do something like this:

    QSqlTableModel adrTableModel;
    adrTableModel.setTable("address");
    adrTableModel.setEditStrategy(QSqlTableModel::OnManualSubmit);
    adrTableModel.setFilter(filter);
    adrTableModel.select();
    
    if (adrTableModel.rowCount() == 1) {
         QSqlRecord addressRecord = adrTableModel.record(0);
         addressRecord.setValue("isUsed", 1);
         adrTableModel.setRecord(0, addressRecord);
         adrTableModel.submitAll();
    }
    

    This works, but I am almost sure that there is an easier and cleaner way to update the record. What is the cleanest way to do it?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2
      adrTableModel.setData(adrTableModel.index(row,column),"isUsed");
      adrTableModel.submitAll();
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

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

        Hi,

        Do you mean programmatically or through a GUI ?
        In the first case, there's nothing particularly wrong with what you wrote.

        You can also use setData.

        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

        • Login

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