-
Suggestion
-
Resolution: Fixed
-
P3: Somewhat important
-
None
-
None
-
b4c63b89d (dev)
The current design of QSqlDatabase is hostile to multithreading (which is quite common these days). For one, the public API forces anyone to add and remove databases to/from a global table, yet each thread can only access database objects created in its own, rendering the global table pointless. For two, the fact that a database objects cannot be moved poses serious design problems. No longer can QSqlDatabase be created at construction time; instead, a special init() function must be provided if a QObject is intended to live in another thread. In addition, any QObject has a non-overridable moveToThread() method, yet some of them (referring to any QSqlDatabase) must have thread affinity fixed or risk undefined behavior. I believe this violates Liskov substitution principle and thus pokes a hole in the objected oriented design.
To fix this, the global table should become optional. QSqlDatabase also must be allowed to move to another thread; or as what other database library do, be able to be accessed in any thread provided that it is not accessed simultaneously.
For Gerrit Dashboard: QTBUG-39957 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
460190,24 | QSqlDatabase: add moveToThread()/currentThread() | dev | qt/qtbase | Status: MERGED | +2 | 0 |