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的
我真的很感激您的幫助!
也許你不應該在每次調用__mutation_handler時創建一個新的通告實例? –