Example:
class MyClass(QObject):
signal_1 = pyqtSignal(str, int)
signal_2 = pyqtSignal(int, int)
signal_3 = pyqtSignal(str, int, int)
Let's say each of these signals is connected elsewhere to perform various functions, however, there's a specific function I want to be performed as well when any of the signals are emitted. What this indiscriminate function does cares only about, say, the last int
argument emitted with the signal. The slot would ostensibly look like:
class OtherClass(QObject):
...
@pyqtSlot(int)
def unifiedResponse(self, index):
# Here I would do something with that index
Is there a way to connect some arbitrary number of signals with arbitrary arguments either directly to a slot or to a repeater signal?
If there is a way to define a slot like so:
@pyqtSlot(???)
def unifiedResponse(self, *args):
important_var = args[-1]
Then I could simply capture the last argument as such. However, I have been unsuccessful in determining how to form the slot signature.
Update:
I may have answered my own question, using lambda
s:
signal_1.connect(lambda _, source: OtherClass.unifiedResponse(source))
signal_2.connect(lambda _, source: OtherClass.unifiedResponse(source))
signal_3.connect(lambda _, _, source: OtherClass.unifiedResponse(source))
The solution from @eyllanesc below however is preferred, as it allows for more flexibility the larger the signal count.