我希望将QThread finish()信号连接到带有参数的插槽,但是只有在没有参数的情况下,它才有效。
目标是在flow_iteration1_finished方法的stage_match方法中使用参数。
主线程:
stage_match方法已连接到我的小部件上的按钮
def stage_match(self):
# Creates thread
#Directory
directory = "{0}/Stage Match".format(ValveSizingDirectory[-1])
#Subdirectory
subdirectory = "{0}/Sheet{1}".format(directory,buttonId)
#Flow file
flowfile = "Calculate{0}".format(buttonId)
#Subdir/Flow file
filename_dir = '{0}/{1}'.format(subdirectory,flowfile)
self.flowiter1 = flowIteration1(subdirectory,flowfile)
# Unable to add arguments, any way to achieve this ?
# self.flowiter1.finished.connect(self.flow_iteration1_finished(filename_dir,flowfile))
# works but doesn't pass arguments
self.flowiter1.finished.connect(self.flow_iteration1_finished)
self.flowiter1.start()
def flow_iteration1_finished(self,filename_dir,flowfile):
#do something with filename/flowfile parameters
pass
要使用的QThread:
class flowIteration1(QtCore.QThread):
"""Thread to run flow iteration1-original"""
def __init__(self,dir,name, parent = None):
super().__init__(parent)
self.dir = dir
self.name = name
def run(self):
from subprocess import call
call("ZCSP {0}.ZCSP {0}.OUT".format(self.name),cwd="{0}".format(self.dir),shell=False)
同样,我对实际线程没有问题,我只是想将QThread的完成信号连接到带有参数的插槽上
stage_match方法中的语句带有已注释掉的参数,我会收到此错误;
TypeError:参数1具有意外的类型'NoneType'