我有几个需要更新的对象。更新在单独的线程中完成,结果将通过pyqtSignal
传输到对象。因此,更新方法会循环遍历所有对象:
对象类:
class MyObject(QObject):
def __init__(self, id):
QObject.__init__(self)
self.id = id
def catch_result(self, id, res):
if id == self.id:
# do something with res
工人阶级:
class Worker(QObject):
result = pyqtSignal('QString', 'QString')
def __init__(self):
QObject.__init__(self)
self.objects = []
# create some objects here
def update_one(self, obj):
# do some computation -> will produce res
self.result.emit(obj.id, res)
def update_all(self):
for obj in objects:
self.result.connect(obj.catch_result)
self.update_one(obj)
self.result.disconnect(obj.catch_result) # is this safe?
当广告catch_result
与信号result
断开连接时,它已经被发出。从我到目前为止所理解的,在发出信号之后,它将被放置在接收器队列中并相应地进行处理。但是假设在调用插槽之前信号将被断开,插槽是否仍然可以正确执行?是否可以节省在调用它们之前断开插槽,但是在发出相应的信号之后?