QSqlDatabase is not thread safe and can not be used from multiple threads. This is however done massively in Akonadi.
Qt 5.11 will print millions of warnings due to this as they are now warning if you do this wrong.
Actually, it might not be that wrong, it is just that QSqlQuery is at least temporarily in an illegal state when constructored by the querybuilder.
Yes upon further investigation this mainly seems to be trigger by the use of default constructed QSqlQuery as a non-initialized null value, but that is not how Qt treats them, and they will try to connect to the default database and prepare to execute commands there.
I wrote this change that seems to stop most of them: https://phabricator.kde.org/D11273
The change in Qt that triggers this is https://codereview.qt-project.org/#/c/213515/
Git commit 02445c3022c96c4cf8734034ec49c0cb9b05d1ea by Albert Astals Cid, on behalf of Allan Sandfeld Jensen.
Committed on 15/03/2018 at 16:39.
Pushed by aacid into branch 'master'.
Fix QSqlQuery warnings
A default constructed QSqlQuery is not a passive null-value but a
query prepared for the default database which may not be allowed
in the current thread. Instead try connecting to the akonadi default
Reviewers: mlaurent, dvratil
Reviewed By: dvratil
Subscribers: dvratil, ngraham, #kde_pim
Differential Revision: https://phabricator.kde.org/D11273
M +4 -4 src/server/handler/fetchhelper.cpp
M +2 -2 src/server/handler/list.cpp
M +2 -1 src/server/storage/querybuilder.cpp