I have a 'small but long' task. On a user request, the query to database should happen, this query can run for some noticeable time.
So this task is moved to a thread with a run() like this:

Qt Code:
  1. void SubTask::run() {
  2. const QString connName = QString::number((quintptr)QThread::currentThreadId());
  3. QSqlDatabase db2 = QSqlDatabase::cloneDatabase(db, connName); // db is SQLite database created in the main thread
  4. if (!db2.open()) {
  5. err = "Failed to open db connection" + connName;
  6. qCritical() << err;
  7. }
  8. QSqlQuery qry(db2);
  9. qry.exec( .... );
  10. qry,clear();
  11. db2.close();
  12. QSqlDatabase::removeDatabase(connName);
  13. }
To copy to clipboard, switch view to plain text mode 

It works fine, query is executing each time user requests it.
But in the console I have a warning:
Qt Code:
  1. QSqlDatabasePrivate::removeDatabase: connection '140551504512768' is still in use, all queries will cease to work.
To copy to clipboard, switch view to plain text mode 
One such warning for each execution.

What am I doing wrong? How the connection should be closed correctly?