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:
Qt Code:
  1. #include <QtCore>
  2. #include <QtSql>
  3.  
  4. class Client: public QRunnable
  5. {
  6. public:
  7. virtual void run();
  8. };
  9.  
  10. void Client::run()
  11. {
  12. {
  13. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", QString::number((unsigned long long)QThread::currentThreadId()));
  14.  
  15. db.setHostName("localhost");
  16. db.setDatabaseName("test");
  17. db.setUserName("me");
  18. db.setPassword("mypass");
  19.  
  20. db.open();
  21.  
  22. //QSqlQuery q(strQuery);
  23. }
  24.  
  25. QSqlDatabase::removeDatabase(QString::number((unsigned long long)QThread::currentThreadId()));
  26.  
  27. }
  28.  
  29. int main(int argc, char *argv[])
  30. {
  31. QCoreApplication a(argc, argv);
  32.  
  33. QThreadPool pool;
  34. pool.setMaxThreadCount(100);
  35.  
  36. for (int i = 0; i < 100; ++i)
  37. {
  38. Client *client = new Client;
  39. bool started = pool.tryStart(client);
  40. Q_ASSERT(started);
  41. }
  42.  
  43. pool.waitForDone();
  44.  
  45. //return a.exec();
  46. return 0;
  47. }
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