<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On 18 August 2014 19:51, Igor Mironchik <span dir="ltr"><<a href="mailto:igor.mironchik@gmail.com" target="_blank">igor.mironchik@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi.<br>
<br>
Well, but with SQLite this approach works...<br>
<br>
-----Original Message-----<br>
From: Sze Howe Koh<br>
Sent: Monday, August 18, 2014 12:57 PM<br>
To: Igor Mironchik<br>
Subject: Re: [Interest] QThreadPool & writing to the DB<br>
<br>
Hi Igor,<br>
<div class=""><br>
On 18 August 2014 14:26, Igor Mironchik <<a href="mailto:igor.mironchik@gmail.com">igor.mironchik@gmail.com</a>> wrote:<br>
> Hi.<br>
><br>
> I want to move write to DB operation to another thread (from the GUI<br>
> thread). And I implemented the following QRunnable:<br>
<br>
</div><snip><br>
<div class="">> Is it OK to launch this runnable every time when I need to write to the<br>
> log?<br>
<br>
</div><snip><br>
<div class="">> And what if previous operation is still not finished and I will launch<br>
> another?<br>
<br>
</div>According to <a href="http://qt-project.org/doc/qt-5/threads-modules.html" target="_blank">http://qt-project.org/doc/qt-5/threads-modules.html</a>, your<br>
queries must be made from the same thread which opened the database<br>
connection. You cannot use QRunnable, because it doesn't let you<br>
choose which thread to use.<br>
<br>
If you want to make queries in another thread, you must create a<br>
QSqlDatabase in that thread, and associate every QSqlQuery with that<br>
QSqlDatabase. Then, run every query from that same thread.<br>
<br>
See the QThread documentation for examples on how to set up your<br>
thread: <a href="http://qt-project.org/doc/qt-5/QThread.html" target="_blank">http://qt-project.org/doc/qt-5/QThread.html</a><br>
<br>
<br>
Regards,<br>
Sze-Howe<br>
<br>
_______________________________________________<br>
Interest mailing list<br>
<a href="mailto:Interest@qt-project.org">Interest@qt-project.org</a><br>
<a href="http://lists.qt-project.org/mailman/listinfo/interest" target="_blank">http://lists.qt-project.org/mailman/listinfo/interest</a><br>
</blockquote></div><br></div><div class="gmail_extra">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.</div><div class="gmail_extra">
<br></div><div class="gmail_extra"><a href="https://github.com/benlau/dquest/blob/DEV_0_3/src/dqthread.cpp">https://github.com/benlau/dquest/blob/DEV_0_3/src/dqthread.cpp</a><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">
<br></div></div>