@
chengxiao ```
class BaiduYunObject(QObject):
stop_procession_signal=pyqtSignal()
def __init__(self,parent=None):
super(BaiduYunObject,self).__init__(parent)
def main(self):
print(11)
self.stop_procession_signal.emit()
class BaiduYunProcessingThread(QObject):
def __init__(self,detect_url,search_url,add_url,multi_search_url):
super().__init__()
self.process_thread= QThread()
self.process_thread1= QThread()
self.procession=BaiduYunObject()
self.procession.moveToThread(self.process_thread1)
self.procession.moveToThread(self.process_thread)
self.process_thread.started.connect(self.procession.main)
self.process_thread1.started.connect(self.procession.main)
self.procession.stop_procession_signal.connect(self.stop_process) #线程结束信号槽
self.process_thread.start()
self.process_thread1.start()
def stop_process(self):
self.process_thread.quit()
```
我创建了两个线程实例测试了下,是能打印出两个 11.但是 11 前面报了下面这个错误:
QObject::moveToThread: Current thread (0x1d0369badf0) is not the object's thread (0x1d068d35530).
Cannot move to target thread (0x1d068d35f50)
所以我有点疑问,不知道这样创建合不合理。而且还有个问题是如何使用循环创建多个线程实例,比如创建 16 个线程应该如何用 for 循环动态创建变量,毕竟 format()只能用于字符串,如果想要循环创建形如 process_thread_1,process_thread_2 这样的变量该怎么创建呢,我试过 locals(),但没成功,希望能给点建议。