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

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Wed Jan 23 14:41:55 CET 2013


> So if someone just says he prefers one approach over all the others,
> it's because he doesn't fully understand the pros and cons for the
> choices. And that's why your question is wrong. There is no right
> choice. Which fortunately for you is exactly what you had in the mail
> subject :)

Fortunately I also mentioned something to that effect in the body as well! :)

<snip>
...
Clearly, if done carefully, both methods work as intented.
</snip>

The semantics of #1, even though relatively cumbersome for trivial
stuff, make it _less_ error prone because there are certain things
being made explicit. Like calling a moveToThread(workerthread) would
remind a reader that the any auto-connections are going to get queued
and the connected slots will be executed in the worker threads
context.

Threads can be tricky, even with nice wrappers like Qts QThread class.
But sometimes there's absolutely no recourse but to use them (as we
found in our embedded project, where we ended up using both
approaches).

My idea for this mail was not to elicit a response for finding _the_
prefect way if doing threading, but rather to figure out what common
scenario's are best dealt with the different approaches at hand.
Though it might not have been worded properly.

I guess the QThread docs can be 'reworded' to indicate that both
approaches are acceptable and list their pro's, cons & possible
pitfalls. Currently, it list both methods, but has a bias towards #1.

Thanks for your input.

-mandeep



More information about the Interest mailing list