Ok, good to know. But I noticed the error happens when I add and remove the connection from the same thread either, but less regular.
The issue can be noticed with the following code sample:
#include <QtCore>
#include <QtSql>
class Client: public QRunnable
{
public:
virtual void run();
};
void Client::run()
{
{
db.setHostName("localhost");
db.setDatabaseName("test");
db.setUserName("me");
db.setPassword("mypass");
db.open();
//QSqlQuery q(strQuery);
}
}
int main(int argc, char *argv[])
{
QThreadPool pool;
pool.setMaxThreadCount(100);
for (int i = 0; i < 100; ++i)
{
Client *client = new Client;
bool started = pool.tryStart(client);
Q_ASSERT(started);
}
pool.waitForDone();
//return a.exec();
return 0;
}
#include <QtCore>
#include <QtSql>
class Client: public QRunnable
{
public:
virtual void run();
};
void Client::run()
{
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", QString::number((unsigned long long)QThread::currentThreadId()));
db.setHostName("localhost");
db.setDatabaseName("test");
db.setUserName("me");
db.setPassword("mypass");
db.open();
//QSqlQuery q(strQuery);
}
QSqlDatabase::removeDatabase(QString::number((unsigned long long)QThread::currentThreadId()));
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QThreadPool pool;
pool.setMaxThreadCount(100);
for (int i = 0; i < 100; ++i)
{
Client *client = new Client;
bool started = pool.tryStart(client);
Q_ASSERT(started);
}
pool.waitForDone();
//return a.exec();
return 0;
}
To copy to clipboard, switch view to plain text mode
Here goes the output of two successive runs:
mushroom@ubuntu:~/projects/mysqltest/mysqlthread/debug$ ./mysqlthread
Error in my_thread_global_end(): 48 threads didn't exit
mushroom@ubuntu:~/projects/mysqltest/mysqlthread/debug$ ./mysqlthread
Error in my_thread_global_end(): 33 threads didn't exit
Error in my_thread_global_end(): 85 threads didn't exit
Bookmarks