具有任意类型参数的 PyQt 信号 / PyQt_PyObject 相当于新型信号
我有一个对象,它应该通过发出一个以新值作为参数的信号来表明值已更改。值的类型可以改变,所以我不确定如何编写信号类型。我知道我可以使用像这样的旧式信号来完成此操作:
self.emit(SIGNAL("valueChanged(PyQt_PyObject)"), newvalue)
但是我将如何使用新式信号来编写它?
我知道与此相关的之前的问题但那里没有给出“真正的”答案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您发出的对象需要将信号定义为其类的属性:
请注意,该信号有一个object类型的参数,该参数应该允许任何内容通过通过。然后,您应该能够使用任何数据类型的参数从类内发出信号:
First, the object you're emitting from needs the signal defined as an attribute of its class:
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:
我是一个初学者,这是我试图回答的第一个问题,所以如果我误解了这个问题,请道歉...
以下代码发出一个发送自定义 Python 对象的信号,并且插槽使用该信号
类打印“Hello World”。
I'm a beginner and this is the first question I'm attempting to answer, so apologies if I have misunderstood the question...
The following code emits a signal that sends a custom Python object, and the slot uses that
class to print "Hello World".