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. setRecord is putting the record in the table but not saving it in the database

setRecord is putting the record in the table but not saving it in the database

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 417 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.
  • AsimovA Offline
    AsimovA Offline
    Asimov
    wrote on last edited by
    #1

    Re: QSqlRecord saving changed does not work
    I have the same problem as Andy314 had a year ago, and his post is marked unsolved.
    Here is my cut down code

    QSqlRecord r = modelContents->record(0);
     r.setValue("boxID",modelBox->record(index.row()).value("boxID").toInt());
    bool ok = modelContents->setRecord(0, r);
    modelContents->submitAll();
    

    Basically I get the value of id from another table.
    Anyway this all works without errors and on screen I can see it has entered the id in the column, but for some reason it is not saving it in the sqlite database.

    However if I double click on this cell and click enter it will save it then.
    The id column will be a hidden column when it is finished. I am just keeping the column shown for now so I can see if the value is being filled.

    So the code appears to be working, but the database is not being updated.
    Any help would be appreciated.

    1 Reply Last reply
    0
    • AsimovA Offline
      AsimovA Offline
      Asimov
      wrote on last edited by
      #2

      I solved my problem a different way, but would still like an answer to the above question.
      I solved it my using a different command

      modelContents->setData(modelContents->index(0, 1),modelBox->record(index.row()).value("boxID").toInt());
      modelContents->submitAll();
      

      Although I am not sure why the previous code didn't work, but the new code is shorter and actually adds to my database ok.

      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