如何将 PyQt 插槽从后台线程连接到 gui 线程
我希望以 pythonic 方式将后台线程中的信号连接到 GUI 线程中的插槽。
我有以下代码片段。
from PyQt4.QtCore import *
class CompanyPresenter(QObject):
fieldChangeSignal = pyqtSignal(str, str)
def __init__(self,model,view):
self.model = model # a CompanyModel
self.view = view # a CompanyView
self.fieldChangeSignal.connect(view.setField)
我收到此错误(在连接线上)
TypeError: pyqtSignal 必须绑定到 QObject,而不是 'CompanyPresenter'
但 CompanyPresenter 继承自 QObject,因此它是 QObject。怎么了?
(我希望 Presenter 和 GUI 最终在不同的线程中运行,但我还没有做到这一点。还没有线程)。
I wish to connect up a signal in the background thread to a slot in the GUI thread in a pythonic way.
I have the following code snippet.
from PyQt4.QtCore import *
class CompanyPresenter(QObject):
fieldChangeSignal = pyqtSignal(str, str)
def __init__(self,model,view):
self.model = model # a CompanyModel
self.view = view # a CompanyView
self.fieldChangeSignal.connect(view.setField)
I get this error (on the connect line)
TypeError: pyqtSignal must be bound to a QObject, not 'CompanyPresenter'
But CompanyPresenter inherits from QObject so it is a QObject. What is happening?
(I want the Presenter and GUI to run in different threads eventually, but I have not got that far yet. There is no threading yet).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你忘记了这个:
添加这个就可以了。(已测试)
you forgot this:
add this will work.(tested)