Unsolved QSqlRecord saving changed does not work
-
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 ?
-
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?
-
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.
-
@Andy314
Its code when its best.. ;)