問題の説明:
- データベースを保持するサーバー プロセス (キャッシュ可能)
- データを読み込んで 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 のイベント ループに適合させています。
本当にありがとうございました!!!