Hey bera82
Remember that each connection to the DB must be uniquely named ...
I use the following when working with dbconns inside threads:
// create a unique database connection to serve this thread
// two calls to rand() are a bit expensive but *effective*...
// note: this is for a PostgreSQL connection ..
sprintf(dbUnique, "myDB%x%x", rand(), rand() );
// set needed conn parameters here...
// whatever code...
QSqlQuery query
(myDB
);
// this is the important part: access it by its unique name.
// remember to close after you're done... (or upon the thread's destruction)
myDB.close();
// create a unique database connection to serve this thread
// two calls to rand() are a bit expensive but *effective*...
// note: this is for a PostgreSQL connection ..
sprintf(dbUnique, "myDB%x%x", rand(), rand() );
myDB = QSqlDatabase::addDatabase ( "QPSQL", dbUnique );
// set needed conn parameters here...
// whatever code...
QSqlQuery query(myDB); // this is the important part: access it by its unique name.
// remember to close after you're done... (or upon the thread's destruction)
myDB.close();
To copy to clipboard, switch view to plain text mode
HTH,
Pedro Doria Meunier
Bookmarks