-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
4.8.x
-
None
-
Ubuntu 12.04
libqtcore4 - 4:4.8.1-0ubuntu4.8
libmysqlclient18 - 5.5.43-0ubuntu0.12.04.1
Scenario:
- In main thread:
- Create database connection.
- Open the connection, close the connection.
- In another thread:
- Create another database connection.
- Set it up so open() fails (e.g. mistype user name or password).
- Open the connection, close the connection.
- Remove database connection
- In main thread:
- Wait for another thread to exit.
- Remove database connection.
- Exit
The result is that the process is blocked for 5 sec and the following is printed:
Error in my_thread_global_end(): 1 threads didn't exit
The following code illustrates the issue:
main.cpp
// build steps: // qmake -project "QT -= gui" "QT += sql" // qmake // make #include <QtDebug> #include <QCoreApplication> #include <QDateTime> #include <QThread> #include <QSqlDatabase> #include <assert.h> void connectOk(const QString & connectionName) { QSqlDatabase db = QSqlDatabase::database(connectionName); assert(db.isValid()); db.setHostName("localhost"); db.setDatabaseName("test"); db.setUserName("root"); db.setPassword(""); bool result = db.open(); assert(result == true); db.close(); } void connectFail(const QString & connectionName) { QSqlDatabase db = QSqlDatabase::database(connectionName); assert(db.isValid()); db.setHostName("localhost"); db.setDatabaseName("testaaaaaaaa"); db.setUserName("root"); db.setPassword(""); bool result = db.open(); assert(result == false); db.close(); } class MyThread : public QThread { private: virtual void run() { const QString connectionName("bbb"); QSqlDatabase::addDatabase("QMYSQL", connectionName); // connectOk(connectionName); connectFail(connectionName); QSqlDatabase::removeDatabase(connectionName); } }; int main(int argc, char * argv[]) { QCoreApplication app(argc, argv); qDebug() << QDateTime::currentDateTime().toString(Qt::ISODate) << " Start"; const QString connectionName("aaa"); QSqlDatabase::addDatabase("QMYSQL", connectionName); connectOk(connectionName); // connectFail(connectionName); MyThread th; th.start(); th.wait(); QSqlDatabase::removeDatabase(connectionName); qDebug() << QDateTime::currentDateTime().toString(Qt::ISODate) << " The End"; return 0; }
The output:
"2015-05-05T13:10:40" Start Error in my_thread_global_end(): 1 threads didn't exit "2015-05-05T13:10:45" The End
If you call connectOk() instead of connectFail() in the thread, the output is:
"2015-05-05T13:17:05" Start "2015-05-05T13:17:05" The End