[Interest] QSqlDatabasePrivate::database: requested database does not belong to the calling thread.

Burak Arslan burak.arslan at arskom.com.tr
Mon Aug 20 09:06:58 CEST 2018


Hello,

When testing our app with the newest Qt, I bumped into the error in the
subject (and nothing works :)).

How are we supposed to use SQLite :memory: databases from multiple
threads where each QSqlDatabase::addDatabase() call creates a new, empty db?

SQLite driver embedded in QtSql is compiled with THREADSAFE=1 [1][2]. So
it's safe to use it from multiple threads. I'm sure not all SQL drivers
come with thread safety guarantees like this, but limiting the
functionality of the whole module just because one or two database
backends are not threadsafe is not the right move.

This should be a big fat warning in the documentation but enforcing it
like this is too harsh.

We are all C++ programmers so we are supposed to know what we are doing
(hahaha :))) It's not Qt's job to protect us from our own choices.

Please revert this change or at least make it driver-specific so those
of us who use SQLite from multiple threads are don't have to patch Qt.

Best regards,
Burak

[1]: https://sqlite.org/compile.html#threadsafe
[2]: You can check it by running PRAGMA compile_options




More information about the Interest mailing list