How to use QThread correctly in pyqt with moveToThread()?

The default run() implementation in QThread runs an event loop for you, the equivalent of: class GenericThread(QThread): def run(self, *args): self.exec_() The important thing about an event loop is that it allows objects owned by the thread to receive events on their slots, which will be executed in that thread. Those objects are just QObjects, … Read more

How to safely destruct a QThread?

The Safe Thread In C++, the proper design of a class is such that the instance can be safely destroyed at any time. Almost all Qt classes act that way, but QThread doesn’t. Here’s the class you should be using instead: // Thread.hpp #include <QThread> public Thread : class QThread { Q_OBJECT using QThread::run; // … Read more

Starting QTimer In A QThread

As I commented (further information in the link) you are doing it wrong : You are mixing the object holding thread data with another object (responsible of doIt()). They should be separated. There is no need to subclass QThread in your case. Worse, you are overriding the run method without any consideration of what it … Read more

How to Compress Slot Calls When Using Queued Connection in Qt?

QCoreApplication QMetaCallEvent Compression Every queued slot call ends up in the posting of a QMetaCallEvent to the target object. The event contains the sender object, the signal id, the slot index, and packaged call parameters. On Qt 5, the signal id generally doesn’t equal the value returned by QMetaObject::signalIndex(): it is an index computed as … Read more

Qt signals (QueuedConnection and DirectConnection)

You won’t see much of a difference unless you’re working with objects having different thread affinities. Let’s say you have QObjects A and B and they’re both attached to different threads. A has a signal called somethingChanged() and B has a slot called handleChange(). If you use a direct connection connect( A, SIGNAL(somethingChanged()), B, SLOT(handleChange()), … Read more