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 codeQSqlRecord 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. -
I solved my problem a different way, but would still like an answer to the above question.
I solved it my using a different commandmodelContents->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.