[Interest] QSqlQuery

Igor Mironchik igor.mironchik at gmail.com
Sun Jan 26 21:24:58 CET 2014



> Igor Mironchik schreef op 26-1-2014 16:29:
>> Hi.
>>
>> I have some questions about database support in Qt 5.
>>
>> First of all, is it safe to transfer a QSqlQuery instance from one 
>> thread to another to process him in another thread. I.e. I want to 
>> execute SELECT query on "DB" thread and return a QSqlQuery from that 
>> thread to the GUI thread, where I will navigate and show users the 
>> result of the query.
>>
> No, that is not safe. You can use database access from threads, but 
> every thread needs it own QSqlDatabase instance of the database 
> connection. The documentation states:
> "A connection can only be used from within the thread that created it. 
> Moving connections between threads or creating queries from a 
> different thread is not supported."
> (http://qt-project.org/doc/qt-4.8/threads-modules.html#threads-and-the-sql-module)

I will not use QSqlDatabase in another thread. I want to create 
QSqlDatabase connection in worker thread and execute queries in that 
thread... For SELECT statemetsa I want to return QSqlQuery object from 
worker thread to the GUI one. Is it safe to use QSqlQuery in another 
thread that created him?

-- 
Best Regards,
Igor Mironchik.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140126/98dc49a0/attachment.html>


More information about the Interest mailing list