我正在尝试运行一个长期运行的测试套件作为PyQt的后台线程。在osx上,线程永远不会运行,但是在Windows上,如果在启动线程后包含print语句,则线程会运行。代码如下所示:
def runModuleTests(self):
self.stackedWidget.setCurrentIndex(2)
self.testThread = QtCore.QThread()
tr = TestRunner(self.on_testResult, self.moduleArticleNumber, self.moduleSerialNumber, self.testBedArticleNumber)
tr.moveToThread(self.testThread)
tr.testFinished.connect(self.testThread.quit)
self.testThread.started.connect(tr.runModuleTests)
self.testThread.start()
print "This print out is here to make threads work. UGLY HACK!"
我有这些问题:
我从这个问题的答案中汲取灵感: Background thread with QThread in PyQt
答案 0 :(得分:0)
来自@Zaiborg的评论是我所遗漏的。即使将对象移动到线程,也需要对对象保持句柄。