Hi,

The QtSql classes themselves are not set to be reentrant or thread-safe so even 
if the SQL driver side is thread-safe there is no guarantee that the Qt side 
will be. What QtSql has always indicated is that you can use a QSqlDatabase to 
the same database in another thread but it has not been possible to share that 
object across threads, granted it may have worked by chance before but this was 
never guaranteed.

Granted the ":memory:" case is a unique one in this regard because opening 
another QSqlDatabase on ":memory:" will give you a new one, however it seems 
you can do:

  ":memory:?cache=shared"

To get it to access the same one. Does that help then?

Regards,
Andy

Interest på vegne av Burak Arslan 
<interest-bounces+andy.shaw=qt...@qt-project.org på vegne av 
burak.ars...@arskom.com.tr> skrev følgende den 20.08.2018, 09:07:

    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
    
    _______________________________________________
    Interest mailing list
    Interest@qt-project.org
    http://lists.qt-project.org/mailman/listinfo/interest
    

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to