[Interest] QThreads: There's no one way to "do it right"! :)

Konstantin Tokarev annulen at yandex.ru
Wed Jan 23 08:56:55 CET 2013



23.01.2013, 11:42, "Mandeep Sandhu" <mandeepsandhu.chd at gmail.com>:
> First I thought "I was doing it right"
>
> Then they said "you're doing it wrong"
> (http://blog.qt.digia.com/blog/2010/06/17/youre-doing-it-wrong/)
>
> Then I thought "I _finally_ got it right"!!
>
> Now they say "You were not doing so wrong"
> (http://woboq.com/blog/qthread-you-were-not-doing-so-wrong.html)!! :D
>
> End of my Cute poem! :P
>
> Jokes apart, which method do most ppl here prefer when doing threading?
>
> Clearly, if done carefully, both methods work as intented.
>
> My rule of thumb is that, if you're doing a simple but compute
> intensive task where you don't want communication via signal/slots
> (probably thats what the author of the last post meant by not needing
> event loop), go with subclassing QThread.

Actually, you *can* communicate with outside world by emitting signals
in this approach. What you maybe should not do is to have slots in your
thread class because they *won't* run in the working thread.

>
> However, if your worker is a little more complex, where you need to
> maintain state across runs, do signal/slot comm etc, then it's better
> to go with a 'moveToThread()' approach.

-- 
Regards,
Konstantin



More information about the Interest mailing list