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

d3fault d3faultdotxbe at gmail.com
Fri Oct 26 16:42:01 CEST 2012

Woot, it works!!!
http://bayfiles.com/file/pdUj/AGXT3T/CleanThreadingExample.zip [also attached]

Weird, I thought all QObject derived classes required the Q_OBJECT
macro. What are the exact requirements for this? Only if you use
signals/slots in the derived class?

Even weirder, the template/moc workarounds I saw were the exact
opposite of what you suggested: they had the template as the base
class =o.

Thank you Bo, both for arguing with me (sparked the idea) and also for
helping me with the string substitution :-D.

I changed the design a bit. Now the slot receiving the
objectReadyForConnections() signal calls a public method on the thread
helper to get a pointer to the object. It was either that or force the
user to do a static_cast<TheirType*>(aQObjectPointer);

The following blurb is from the comments in the example. It's the only
stuff I'm not quite sure about. It's a bit OT since I don't even use
an infinite loop.

Note: if your backend slot enters an infinite loop, you should
periodically call QCoreApplication::processEvents() manually... or
else your backend thread will never process the QThread::quit() event
or any signals sent to your other slots. If you do take that approach,
you should check this->thread()->isRunning() right after the call to
processEvents()... and then return or otherwise end the infinite loop
if it's false. Shutting down the thread via QThread::quit() only tells
the thread to quit. Since you're in an infinite loop calling
processEvents() manually, you have the power to ignore it (this is NOT
advised). If QThread::terminate() is called, the thread will be
terminated instantly, possibly losing/corrupting data.

You guys think the objectonthreadhelper.h class has a place within Qt?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: CleanThreadingExample.zip
Type: application/zip
Size: 18720 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121026/60482ba0/attachment.zip>

More information about the Interest mailing list