ok at this place the thread is created..
void FortuneServer::incomingConnection(int socketDescriptor)
{
FortuneThread *thread = new FortuneThread(socketDescriptor, fortune,this);
thread->start();
}
my understanding is whenever the new connection happens (a new client connects to the server)new thread is connected..
I am just trying to build my requirements on existing Threaded Fortune Server example.
yes currently creating a new database connection for each thread. any suggestion on DB connectivity please correct me.
Last edited by meena; 10th May 2010 at 11:06.
Please post the contents of your createConnection() method.
createConnection() is in database.h file & the method is exactly look like this
static bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(" ... ");
if (!db.open()) {
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "
"to build it.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
return false;
}
return true;
}
Last edited by meena; 10th May 2010 at 12:47.
So you are not creating a new connection for each new thread, you are reusing the same connection name each time so only one thread at once is able to communicate with the database. And that's what Qt already told you, you even quoted the message in one of the first posts.
Bookmarks