[Qt-interest] 答复: connect mysql
pengliang(彭亮)
pengliang at founder.com
Mon Sep 26 04:45:07 CEST 2011
Hi
This problem still exist after I modified it as your said.
Thanks
Ken
-----邮件原件-----
发件人: qt-interest-bounces+pengliang=founder.com at qt.nokia.com [mailto:qt-interest-bounces+pengliang=founder.com at qt.nokia.com] 代表 Tony Rietwyk
发送时间: 2011年9月20日 8:40
收件人: qt-interest at qt.nokia.com
主题: Re: [Qt-interest] connect mysql
> Sent: Tuesday, 20 September 2011 7:41 AM
>
> I guess clear() is not enough or there is another query which was not cleared.
> According to documentation you have to make sure no open queries on the
> database connection when this function is called.
> For some reason it does not.
>
> Alex
>
>
> Sent: Tuesday, September 13, 2011 11:32 PM
>
> Hello
> I don t know why application always output that information. Anybody
> could tell me why.
>
>
>
> --------------------------------- snippets
> query.clear();
> f5ErpDb.close();
> f5ErpDb.removeDatabase("QODBC");
>
> camMysqlDb = QSqlDatabase::addDatabase("QMYSQL");
>
>
> ------------------- application output
> 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.
Hi Alex & Pengliang,
QSqlDatabase.close says that it invalidates any queries - it says nothing about them being open or valid at the time. So you need to use block structuring to release the objects entirely:
{
QSqlDatabase f5ErpDb = QSqlDatabase::addDatabase("QODBC");
...
{
QSqlQuery query(f5ErpDb);
...
}
f5ErpDb.close();
QSqlDatabase::removeDatabase("QODBC");
}
{
QSqlDatabase camMysqlDb = QSqlDatabase::addDatabase("QMYSQL");
...
// Etc...
}
Encapsulating each block in its own method is the obvious recommendation!
Hope that helps,
Tony.
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list