[Qt-interest] Sqlite multithreaded application

Jeremy Lainé jeremy.laine at bolloretelecom.eu
Wed Oct 12 14:29:29 CEST 2011


Hello,

I think you'll find the information you need here:

http://doc.qt.nokia.com/4.7/threads-modules.html#threads-and-the-sql-module

Basically you need on QSqlDatabase instance per thread. The following approach has worked 
nicely for me:

- create a "reference" QSqlDatabase in your app's main thread

- write a method which is called whenever you need to access the database, and clones the 
"reference" QSqlDatabase as needed for the current thread using QSqlDatabase::cloneDatabase()

An example:

http://opensource.bolloretelecom.eu/projects/qdjango/browser/src/QDjango.cpp#L84

-- 
Jeremy LAINE
Bolloré telecom | 26, rue de Berri | F-75008 Paris




More information about the Qt-interest-old mailing list