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

前端 未结 2 1525
悲&欢浪女
悲&欢浪女 2020-12-11 03:40

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

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-11 03:57

    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)
    

提交回复
热议问题