QSqlTableModel insertRecord() returns true but nothing is saved in database
-
Fixed the memory leak, but didn't make a difference. QSqlRecord comes from:
@
bool MyStuffDb::addStuff(const MyObject& myobject)
{
QSqlTableModel table(NULL, myDatabase);
table.setTable("myobjects");
QSqlRecord record = myDatabase.record("myobjects");// Call to code in first post return addStuff(myobject, &record, &table);
}
@ -
Did you check what edit strategy is used for the model ? If it's OnManualSubmit then you have to submit your changes
-
I've checked that and tried them all without success. After calling insertRecord() I can see the row was inserted in memory but just not saved to disk, ever. Is there anyway to flush it to disk?
I even switched over to QSqlQuery instead of using QSqlRecord and QSqlTableModel and had the same result. Could this be a linux issue somehow? As I mentioned before I only see this behavior on the first boot off a drive. Works like a charm after that.
-
And if you remove the QSQLITE_ENABLE_SHARED_CACHE option ?
-
Can you create a minimal compilable example that shows this behavior ?
-
You can use e.g. "pastebin":http://pastebin.com
-
In that case check "here":https://gist.github.com/snow45/61cea39423b79c61e10f
Remember I only see this behavior with the setup initially described.
-
I found the problem. I used the command lsattr to look at file attributes on my database files and found that when I opened App 2 for the first time I was deleting the shared database out from under App 1 and recreating it. Just had to fix that and everything works like I would expect.
-
Out of curiosity, how was it doing it ?