[Interest] Fwd: QSqlDatabase and Multithreading

Soroush Rabiei soroush.rabiei at gmail.com
Thu Jan 23 20:34:48 CET 2014


Oops! Sorry I sent mail to sender mail address instead of list.



On Thu, Jan 23, 2014 at 10:34 PM, Soroush Rabiei
<soroush.rabiei at gmail.com>wrote:

> I've locked down all data-intensive operations with QMutexLocker
> (exception-safe?) and moved all operations to another thread using
> QtConcurrent::run() / QFuture / QFutureWatcher. Then GUI is notified when
> data is ready by a signal from QFutureWatcher. Everything is fine
> currently, if there is no bad design or leaks that I cant's see.
>
> I got the wrong perception that a QSqlDatabase can not be used within two
> threads, because it's designed not to be so (asserts caller thread handle
> with some static pointer or some other silly codes in framework).
>
> Do you think the documentation needs one more explaining paragraph, or I'm
> the only one who fails to understand documentation properly?
>
>
>  On Wed, Jan 22, 2014 at 7:14 PM, Thiago Macieira <
> thiago.macieira at intel.com> wrote:
>
>>  On quarta-feira, 22 de janeiro de 2014 18:48:53, Soroush Rabiei wrote:
>> > 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.
>> > My question is how can I make connections between UI and second thread?
>>
>> You may want to look at the producer-consumer QThread examples. You can
>> pass
>> the data in mutex-protected queues or by way of signals & slots.
>>
>> Just be careful that if you use slots, your class should not derive from
>> QThread.
>> --
>> Thiago Macieira - thiago.macieira (AT) intel.com
>>   Software Architect - Intel Open Source Technology Center
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140123/334a9ce2/attachment.html>


More information about the Interest mailing list