When should moveToThread
be preferred over subclassing QThread
?
This link shows that both methods work. On what basis should I decide what to u
As a starting point: use neither. In most cases, you have a unit of work that you wish to run asynchronously. Use QtConcurrent::run for that.
If you have an object that reacts to events and/or uses timers, it's a QObject
that should be non-blocking and go in a thread, perhaps shared with other objects.
Such an object can also wrap blocking APIs.
Subclassing QThread
is never necessary in practice. It's like subclassing QFile
. QThread
is a thread handle. It wraps a system resource. Overloading it is a bit silly.