[Development] QThread usage/guidance

Kevin Krammer kevin.krammer at kdab.com
Sat Oct 6 17:46:17 CEST 2012


On Friday, 2012-10-05, Olivier Goffart wrote:
> On Friday 05 October 2012 15:24:40 Tony Van Eerd wrote:
> > So that is the 'recommended' style then?
> 
> Depends what you want to do.
> If your task is CPU bounded, you can use QtConcurrent.
> If you don't need to event loop, you can reimplement the run() function.
> 
> I'd use this appreach only if your task make use of the eventloop.  For
> example if your worker receive "jobs" from signals from the main thread.
> But if you only have one process() slot that is trigerred only by the
> started signal, it is a bit overkill.
> 
> 
> This mailing list is not really for question on how to use Qt. You should
> use the interest mailing-list or the forums instead.

In principle this is true. However, recurring questions regarding that topic 
indicate that the respective documentation is either incomplete, misleading or 
wrong and documentation is part of the development effort.

For example the blog post linked to from Tony's first email and your 
recommendation above would suggest that the documentation of QThread is not 
sufficiently covering the use of "active" (event loop driven) worker objects.

However, whenever the moveToThread recommendation is advertised, especially 
with workers needing worker-thread event loop processing, I always check if 
the documentation of QTcpServer::nextPendingConnection() has changed.

Because it clearly states that QTcpSocket instances returned by that method 
cannot be used from another thread, making either that note very wrong or 
recommendation of moveToThread() very dangerous.

Cheers,
Kevin
-- 
** Qt Developer Conference: http://qtconference.kdab.com/ **

Kevin Krammer | kevin.krammer at kdab.com | Software Engineer
Klarälvdalens Datakonsult AB, a KDAB Group company
Tel. Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
KDAB - Qt Experts - Platform-independent software solutions
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4712 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20121006/8a72b9a7/attachment.bin>


More information about the Development mailing list