[Interest] Heavily Commented Example: Simple Single Frontend with Two Backends

Charley Bay charleyb123 at gmail.com
Mon Oct 22 12:25:32 CEST 2012


Daniel spaketh:
> You should look into the active object design pattern. The idea is that you
> hide the object that lives in another thread behind a managing object. I
> only discovered this recently and it’s vastly superior to subclassing
> QThread, or using moveToThread or any of that rubbish.

I also am using this pattern, without subclassing QThread.  However, I
still use QThread:

  MyThreadHandle (=>owns=>) QThread (=>owns=>) MyThreadWorker

The rest of my system only has access to "MyThreadHandle", and it's
not derived from QObject, so it is not possible for the rest of the
system to "moveToThread()" any of my thread-safe internals.  (Simple,
safe, and clean.)

> In fact, I don’t use
> QThread at all these days; C++11 (and boost if you don’t have C++11 yet) has
> a better threading model.

Could you elaborate?  One of the reasons I prefer QThread is that the
SIGNAL/SLOT provides a thread-safe signalling/communication bridge
across threads.

--charley



More information about the Interest mailing list