[Qt-interest] QSqlDatabase with Sqlite question

KC Jones kc at asperasoft.com
Thu Nov 19 02:53:45 CET 2009


When my application closes, while attempting to close the Sqlite
database and its connection, I get an error message:

QSqlDatabasePrivate::removeDatabase: connection
'qt_sql_default_connection' is still in use, all queries will cease to
work.

I've searched the list archives and found a mention of this, but I
must be dense since I cannot make the proposed fix work for me.  I'm
closing my connection, which seems from the docs like it should be
sufficient.  When I go to remove the database, I get the error
message.  In my app -- actually in my QTest test cases -- when I
attempt to close one db and open another, I also get the message.

Below is some dead simple code to reproduce my problem.  Could not be
more simple, right?  What am I missing?
I'm running this on Mac 10.5.8, Qt 4.5.1.  The code is:

#include <QtCore>
#include <QtSql>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QSqlDatabase connection = QSqlDatabase::addDatabase("QSQLITE");

    connection.setDatabaseName("./test.db");
    connection.open();
    connection.exec("CREATE TABLE foo ( id integer PRIMARY KEY, bar
integer );"); // everything OK
    connection.close(); // still OK

    QSqlDatabase::removeDatabase(connection.connectionName()); //
triggers warning message

    return a.exec();
}



More information about the Qt-interest-old mailing list