[Interest] QThreadPool & writing to the DB

Ben Lau xbenlau at gmail.com
Thu Aug 28 09:55:18 CEST 2014


On 18 August 2014 19:51, Igor Mironchik <igor.mironchik at gmail.com> wrote:

> Hi.
>
> Well, but with SQLite this approach works...
>
> -----Original Message-----
> From: Sze Howe Koh
> Sent: Monday, August 18, 2014 12:57 PM
> To: Igor Mironchik
> Subject: Re: [Interest] QThreadPool & writing to the DB
>
> Hi Igor,
>
> On 18 August 2014 14:26, Igor Mironchik <igor.mironchik at gmail.com> wrote:
> > Hi.
> >
> > I want to move write to DB operation to another thread (from the GUI
> > thread). And I implemented the following QRunnable:
>
> <snip>
> > Is it OK to launch this runnable every time when I need to write to the
> > log?
>
> <snip>
> > And what if previous operation is still not finished and I will launch
> > another?
>
> According to http://qt-project.org/doc/qt-5/threads-modules.html, your
> queries must be made from the same thread which opened the database
> connection. You cannot use QRunnable, because it doesn't let you
> choose which thread to use.
>
> If you want to make queries in another thread, you must create a
> QSqlDatabase in that thread, and associate every QSqlQuery with that
> QSqlDatabase. Then, run every query from that same thread.
>
> See the QThread documentation for examples on how to set up your
> thread: http://qt-project.org/doc/qt-5/QThread.html
>
>
> Regards,
> Sze-Howe
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>

btw , I have made an implementation that hold a thread and accept QRunnable
on main thread then run it on the created thread. You may take it as a
reference.

https://github.com/benlau/dquest/blob/DEV_0_3/src/dqthread.cpp
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140828/0d55beec/attachment.html>


More information about the Interest mailing list