我正在尝试从QThread
发出信号以更新progressBar
class Signal(QtCore.QObject):
this = QtCore.Signal(int)
class Load(QtCore.QThread):
def __init__(self, parent):
QtCore.QThread.__init__(self, parent)
self.parent = parent
self.onProgress = Signal()
def run(self):
'''
'''
stacks = []
count = 100
for i in range(count):
# do something ...
self.onProgress.this.emit(count)
以及我在MainWindow中如何称呼它
def __init__(self ... ):
...
self.Thread = Load(self)
self.Thread.onProgress.connect(self.onProgress)
self.Thread.start()
@QtCore.Slot(int)
def onProgress(self, int):
self.ui.progressBar.setValue(self.ui.progressBar.value() + (90/int))
但我总是得到这个错误
TypeError: PySide.QtCore.QObject.connect(): not enough arguments
最佳答案
您正在连接到onProgress
,它是Signal
类的实例(在这种情况下,名称具有误导性)。您要连接到onProgress.this
,它是实际的信号对象:
self.Thread.onProgress.this.connect(self.onProgress)
或者,将
onProgress
分配给信号本身:self.onProgress = Signal().this
关于python - TypeError:PySide.QtCore.QObject.connect():参数不足,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32237244/