[Qt-interest] QSqlDatabase duplicate connection problem , when connection name is epecified

charles.yin at nokia.com charles.yin at nokia.com
Mon May 23 02:57:16 CEST 2011


Hi,
You can use QSqlDatabase::database("connectionName"); before you call addDatabase(), for example:

QSqlDatabase db = QSqlDatabase::database("ConnectionTest");
If (!db.isValid()) {
    db = QSqlDatabase::addDatabase("QSQLITE" , "ConnectionTest");
}
....
db.close();

Cheers
Charles

-----Original Message-----
From: qt-interest-bounces+charles.yin=nokia.com at qt.nokia.com [mailto:qt-interest-bounces+charles.yin=nokia.com at qt.nokia.com] On Behalf Of ext Aaron Lewis
Sent: Sunday, May 22, 2011 4:34 PM
To: Qt Interest
Subject: [Qt-interest] QSqlDatabase duplicate connection problem , when connection name is epecified

Hi,
	First of all , should i call QSqlDatabase:;removeDatabase each time
	when finished using it ?

	Besides , i initiate my connection with the following code , in this
	case , it's threaded and use the same database file for all
	QThread based class:

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE" , "ConnectionTest" + rand() % 100);
	blabla..
	db.close(); 

	Which try to take use of different connection name , but i still
	receive the following message in terminal:

	QSqlDatabasePrivate::addDatabase: duplicate connection name 'us connection in worker', old connection removed.

	Is that wired or i missed some part of code ?

	Many thanks.

--
Best Regards,
Aaron Lewis - PGP: 0xDFE6C29E ( http://http://pgp.mit.edu/ ) Finger Print: 9482 448F C7C3 896C 1DFE 7DD3 2492 A7D0 DFE6 C29E _______________________________________________
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