[Interest] QSqlDatabase and threads

Jaime Fernandez j.fernandez at midimesures.fr
Fri May 31 08:56:37 CEST 2013


Hello,

Be careful of mixing thread and mysql :

https://bugreports.qt-project.org/browse/QTBUG-31468

You should protect the calls to addDatabase with a mutex.


Le 30/05/2013 18:31, Karl Ruetz a écrit :
>
> Both the documentation and my own experience say what you are after is 
> not possible:
>
> http://qt-project.org/doc/qt-4.8/threads-modules.html#threads-and-the-sql-module
>
> I do a similar thing only with MySQL.  I am forced to create a 
> QSqlDatabase object with each thread.  If I do not, I get dead locked 
> situations once in awhile.  With Sqlite, I would think there would be 
> some I/O conflicts since the database is actually a file.
>
> A connection per thread seems the only safe way to approach it.
>
> Karl
>
> On 2013-05-30 10:03, Witold E Wolski wrote:
>
>> I am using threading to speed up compuation. Each thread produces 
>> some results which I would like to store in a sqlite file.
>>
>> My idea is to have something like an monitor object which has an  
>> QSqlDatabase member
>> and a insert method which is synchronized using a mutex.
>>
>> The problem I am  actually running into is that the QSqlDatabase 
>> member gets ??? once the pointer to the Monitor object is passed into 
>> to the threads.
>>
>>
>> when asked in the thread it claims to be isOpen and to be isValid but 
>> all the inserts on it fail with
>>
>> insert Feature: Parameter count mismatch
>>
>>
>> On the other hand if I construct the same object within the thread 
>> than everything works fine.
>> So the instert statements are definitely correct.
>>
>> Any ideas ? by the way I am using the tbb for threading.
>>
>> Witold
>>
>>
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org  <mailto:Interest at qt-project.org>
>> http://lists.qt-project.org/mailman/listinfo/interest
>
>
>
> _______________________________________________
> 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/20130531/a2105dc7/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: j_fernandez.vcf
Type: text/x-vcard
Size: 273 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130531/a2105dc7/attachment.vcf>


More information about the Interest mailing list