【发布时间】:2012-08-03 10:26:50
【问题描述】:
我很难将信号与 PyQt4 中的方法连接起来。
我可以将对象 A 的绑定信号与对象 B 的方法连接起来,
但我无法将对象 A 的绑定信号与 self 方法连接起来
(建立连接的对象。)
我究竟做错了什么?见下文:
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 中触发,字符串 hi 在 FooA 中触发,字符串 hi
我希望看到额外的一行,> 在 MainObj 中触发
提前致谢。 比尔
【问题讨论】:
-
按预期工作。确定您发布的代码与您尝试运行的代码相同吗?
-
Confirmed 也适用于我。
标签: pyqt