PDA

View Full Version : multiple pgsql databases in QT with a single QTthread



praveen1
10th September 2012, 17:28
How to open multiple pgsql databases in QT with a single QTthread with diffrenernt user names of the and IP adderess.
hi
I am having to 3 mysql databses at three different IP address with same database name.
My QT application needs to connect all 3 data base at same time and needs to update the tables of all 3 databases.
this is my code:
/* for DB0 */
QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
db.setHostName("10.2.74.222");

db.setDatabaseName("MAIN");

db.setUserName("user1");

db.setPassword("user111");
db.setPort(5437);
if (!db.open())
{
qDebug("OPening database fail");
}

QSqlQuery query("select *",db);

if(!(query.exec()))
{
qDebug("Cannot execute the query ");
}
/* for DB0 */


/* for DB2 */
QSqlDatabase db1 = QSqlDatabase::addDatabase("QPSQL");

db1.setHostName("10.2.74.222");

db1.setDatabaseName("CPSS_DEC11");

db1.setUserName("user1");

db1.setPassword("user111");
db1.setPort(5437);
if (!db1.open())
{
qDebug("OPening database fail");
}

QSqlQuery query1("select *",db1);

if(!(query1.exec()))
{
qDebug("Cannot execute the query verify seccode111");
}
/* for DB2 */

When i am trying to connect all 3 its generating following error:
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.
This version of PostgreSQL is not supported and may not work.


Please help me to solve the problem.

Lesiok
10th September 2012, 17:56
QSqlDatabase::addDatabase have second parameter connectionName.