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

Passing extra arguments through connect

The problem can be solved in 2 ways: Using lambda functions: In general: obj.signal.connect(lambda param1, param2, …, arg1=val1, arg2= value2, … : fun(param1, param2,… , arg1, arg2, ….)) def fun(param1, param2,… , arg1, arg2, ….): […] where: param1, param2, … : are the parameters sent by the signal arg1, arg2, …: are the extra parameters … Read more