[Qt-interest] QSqlDatabase with Sqlite question
Bill King
bill.king at nokia.com
Thu Nov 19 03:05:58 CET 2009
On 11/19/2009 11:53 AM, ext KC Jones wrote:
> 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();
> }
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
It's a bit of a tricky one, but I think it's a hangover from not
reassigning the connection object to an empty QSqlDatabase object, so
the "connection" still maintains a reference count of at least 1 when
you go to remove it. The close doesn't actually decrement the reference
count (nor does the open increment). Personally I'm not happy with the
current semantics, and will have to investigate the cost of changing to
open/close increment/decrement. (Possibly not, especially in 4.6 as it's
a behaviour change, and it's too late to get behaviour changes into 4.6).
Hope this helps,
Bill.
--
Bill King, Software Engineer
Qt Development Frameworks, Nokia Pty Ltd
Brisbane Office
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091119/0255170e/attachment.html
More information about the Qt-interest-old
mailing list