Using sqlite in Qt Application

 I got this error, every time a reopen or open a new database file:
QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work.
QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed.

Sometimes I get lazy and ask google first. This time google didn't tell me.
 A few noobs like me had the same issue. There was discussion about that, but they actually was digging to deep!

The answer is very simple!

Load driver only once:


And then, the database file you can close and open multiple times:


if (db.open())
qDebug() << db.lastError();

qDebug() << db.tables();


No comments:

Post a Comment