【发布时间】:2012-06-24 02:48:57
【问题描述】:
问题描述:
- 保存数据库的服务器进程(可缓存)
- 在 UI (RemoteCache) 中读取和显示数据的客户端
- 他们通过 Twisted PB 互相交谈
- 我想在服务器数据库更改时刷新我的 UI。
我的客户端有一个方法,_mutation_handler,由服务器通知 为了通知我的 UI,我创建了一个发出信号的单例 Notifier 类。 然后在我的 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!!!'
问题: 当我更改服务器数据库中的某些内容时,_mutation_handler 会被调用 正确,那么信号就可以发出了。 但是,MyWidget 无法捕捉到信号。
注意:我正在使用 qt4reactor 来调整 Twisted 的事件循环以适应 qt 的
非常感谢您的帮助!!!
【问题讨论】:
-
也许您不应该在每次调用
__mutation_handler时都创建一个新的 Notifier 实例?
标签: pyqt twisted signals-slots