PyQt signal with arguments of arbitrary type / PyQt_PyObject equivalent for new-style signals


Question

I have an object that should signal that a value has changed by emitting a signal with the new value as an argument. The type of the value can change, and so I'm unsure of how to write the signal type. I know that I can acconmplish this using old-style signals like this:

self.emit(SIGNAL("valueChanged(PyQt_PyObject)"), newvalue)

but how would I write this using new-style signals?

I am aware of a previous question related to this but no "real" answer was given there.

1
9
5/23/2017 11:47:08 AM

First, the object you're emitting from needs the signal defined as an attribute of its class:

class SomeClass(QObject):
    valueChanged = pyqtSignal(object)  

Notice the signal has one argument of type object, which should allow anything to pass through. Then, you should be able to emit the signal from within the class using an argument of any data type:

self.valueChanged.emit(anyObject)
18
3/3/2011 9:10:37 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon