Data base is oppened in application by following code:
db = QSqlDatabase::addDatabase("QSQLITE");
bool dbExists = QFile::exists("base.db");
db.setDatabaseName("base.db"); // ":memory:"
if (!db.open()) {
db.close();
QMessageBox::critical(0, tr("Cannot open database"),
tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "
"to build it."), QMessageBox::Cancel);
return;
}
if (!dbExists)
createDB();
I've mapped some tables to widgets via QDataWidgetMapper. All work fine during application run. Changes take effect. But all the chages are lost after restarting application with existing base.db. Application starts much faster, so it opens this file but with unchanged data base.
I've tried to close application by
db.close();
this->close();
There is no luck. Even the sync query did not help after db.open:
QSqlQuery query(db);
query.exec("PRAGMA synchronous = ON;");
What have I missed to sync changes to base.db?
UPDATE. You can try to build sqlwidgetmapper standard example and change :memory: to "base.db" file. It doesn't save changed data to file too.