PDA

View Full Version : QSqlDatabasePrivate - warning



Tomasz
11th August 2010, 23:21
Hello!

I've wrote application with some functions which uses SQL database. I each function I open and read my database like this:



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

bdb.setDatabaseName("/home/mydatabase.db");
ok = bdb.open();

if (ok)
{
out << endl << "OK!" << endl ;
} else {
out << "Error!" << endl;
}

QSqlQueryModel *queryModel = new QSqlQueryModel;
queryModel->setQuery("SELECT * FROM some_tab where some_field='something'", bdb);

QSqlRecord rec;
//some code...

bdb.close();


but I get warnings like this in my console:



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.


Is it something wrong? Everything works fine, but maybe I should do it in other way?

thanks in advance
best regards
Tomasz

ChrisW67
11th August 2010, 23:34
It is complaining because you open/close the default database connection each time one of these chunks of code executes. The first message is probably when you close the connection because your query model and record a still in scope and "using" the connection. The second is when you open a connection overriding the existing default connection.

Do you really need to recreate the database connection each time or can you open it once and leave the connection open?