我在PyQt4中很难连接信号和方法。 我可以用对象B的方法连接对象A的绑定信号, ,但我无法将对象A的绑定信号与自己的方法 (进行连接的对象)连接。
我是什么做错了?请看下图:在PyQt4中连接信号和自己的方法
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class FooA(QObject):
trigger=pyqtSignal(str)
def receive_trigger(self,a):
print'triggered in FooA, string',a
class MainObj(QObject):
def __init__(self):
self.a1=FooA()
self.a2=FooA()
#I can connect signals and methods of separate objects:
self.a1.trigger.connect(self.a2.receive_trigger)
self.a1.trigger.emit('hi')
#... but I can't connect a signal with a method of self
self.a1.trigger.connect(self.receive_trigger)
self.a1.trigger.emit('hi')
def receive_trigger(self,a):
print 'triggered in MainObj'
执行为: MainObj()
在FooA触发,串喜 在FooA触发,串喜
我期望看到一个额外的行, >在MainObj中触发
在此先感谢。 Bill
按预期为我工作。确定您发布的代码与您尝试运行的代码相同吗? – ekhumoro 2012-08-06 16:47:13
确认的作品也适合我。 – jdi 2012-08-06 20:48:20