Important: Please read the Qt Code of Conduct -

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

  • 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);
    bool ok = modelContents->setRecord(0, r);

    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.

  • 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());

    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.

Log in to reply