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. QSqlRecord saving changed does not work
Forum Update on Monday, May 27th 2025

QSqlRecord saving changed does not work

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.4k 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.
  • Andy314A Offline
    Andy314A Offline
    Andy314
    wrote on last edited by Andy314
    #1

    Hello,
    I have a problem to update an existend record in a database.
    My table consists of some text and some boolean fields.
    Here the basic part of my code:

     QSqlTableModel t;       
    //  configure  db, filter etc.    .........................
    t.select();
    QSqlRecord rec=t.record();  // get an empty record
    //  fill the record fields with values .............
    if(t.recordCount())   // only count = 1 is possible because of my logic
         t.setRecord(0,rec);
    else
       t.insertRecord(0,rec);
    t.submitAll();
    

    The insertRecord part works always .
    The setRecord part only t works if I change a least one boolean field in the record to the opposite value which is stored currently in the DB. Then the text field changes to new values too.
    But If I change only a text field no changes will be transmitted to the DB.
    I get no error, all seem to work but nothing changes in the DB.

    It seem that Qt "thinks" that the record has not changed and skip the storing ?
    Can this be ?
    Why is there a difference betweent bool and string values ?

    How can i fix the problem ?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      have you checked the return value of setRecord ?

      http://doc.qt.io/qt-5/qsqltablemodel.html#setRecord

      Maybe there is something about the text field it don't like?

      1 Reply Last reply
      0
      • Andy314A Offline
        Andy314A Offline
        Andy314
        wrote on last edited by Andy314
        #3

        Yes, I have checked the errors of all function. Nowhere I get an error.
        I set all field to generated true.

        I had debugged a half day. Now the next day all works perfect suddenly without any code change. Misterious! Maybe some database log issue ???

        Thank you for your help.

        mrjjM 1 Reply Last reply
        1
        • Andy314A Andy314

          Yes, I have checked the errors of all function. Nowhere I get an error.
          I set all field to generated true.

          I had debugged a half day. Now the next day all works perfect suddenly without any code change. Misterious! Maybe some database log issue ???

          Thank you for your help.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Andy314
          Its code when its best.. ;)

          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