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

C++ Qt signal and slot not firing

Add Q_OBJECT to your class, like this: class MainWidget : public QWidget { Q_OBJECT You also have to run moc to generate some helper code. qmake does that automatically for your, but if you compile this yourself, you need to run moc.

How do I assert the identity of a PyQt5 signal?

Signals as entities are created each time you invoke it as they represent a different connection: In [1]: import sys In [2]: from PyQt5 import QtWidgets In [3]: app = QtWidgets.QApplication(sys.argv) In [4]: button = QtWidgets.QPushButton() In [5]: id(button.clicked) Out[5]: 140150155639464 In [6]: id(button.clicked) Out[6]: 140150154507528 In [7]: id(button.clicked) Out[7]: 140150155640184 In [8]: id(button.clicked) Out[8]: … 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

Declare abstract signal in interface class

As I found out in the last days… the Qt way of doing this is like this: class IEmitSomething { public: virtual ~IEmitSomething(){} // do not forget this signals: // <- ignored by moc and only serves as documentation aid // The code will work exactly the same if signals: is absent. virtual void someThingHappened() … Read more

QtCore.QObject.connect in a loop only affects the last instance

Put the loop variable in a default argument, like this: lambda state, instance=instance: findInstance.projectsInstance.myslot( “TWCH”, findInstance, instance.text(), instance.checkState(), instance) This will give each lambda its own local copy of the instance variable. EDIT Here’s a simple script that demonstrates how to use default lambda arguments: from PyQt4 import QtGui class Window(QtGui.QWidget): def __init__(self): QtGui.QWidget.__init__(self) layout … Read more