2012-06-21 76 views
0

问题描述:与扭曲PyQt的信号:不能赶上自定义信号

  • 一个服务器进程其保持数据库(可缓存)
  • 客户端,其读取并在UI(RemoteCache)显示数据
  • 他们通过扭曲的PB彼此交谈
  • 我想在服务器数据库更改时刷新我的UI。

我的客户有一个方法,_ 突变 _handler,这是由服务器 通知通知我的UI,我创建了一个发出信号单身通知程序类。 然后在我的Qt小部件中,我将信号连接到小部件的插槽。

# inside the RemoteCache subclass on my client 
# notified by the PB server when something happens 
def __mutation_handler(self): 
    notifier = Notifier() 
    notifier.notify() 

# inside notify.py 
class Notifier(QObject): 
    def __new__(cls): 
    # Make it a singleton 
    def notify(self): 
    self.emit(SIGNAL('SomethingChanged')) 

# inside the RemoteCache subclass on my client 
def __mutation_handler(self): 
    # singleton notifier 
    notifier = Notifier() 
    notifier.notify() 
# inside my widget.py 
class MyWidget(QWidget): 
    def __init__(self): 
    ... # code 
    self.notifier = Notifier() 
    self._create_signal_slot_connections() 
    ... # more code 
    def _create_signal_slot_connections(self): 
    self.connect(self.notifier, SIGNAL('SomethingChanged'),self.shout) 
    def shout(self): 
    print 'Server's database changed!!!' 

问题: 当我改变我的服务器的数据库中获得一些东西,_ 突变 _handler被正确调用 ,然后将信号发射好吗。 但是,MyWidget无法捕捉信号。

注:我使用qt4reactor适应Twisted的事件循环,以适应Qt的

我真的很感激您的帮助!

+0

也许你不应该在每次调用__mutation_handler时创建一个新的通告实例? –

回答