TypeError: PySide.QtCore.QObject.connect(): not enough arguments

TypeError: PySide.QtCore.QObject.connect(): not enough arguments

我正在尝试从 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)

以及我如何在主窗口中调用它

    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 class 的一个实例(在本文中是一个误导性的名称)。您想要连接到 onProgress.this,这是实际的信号对象:

self.Thread.onProgress.this.connect(self.onProgress)

或者将 onProgress 分配给信号本身:

self.onProgress = Signal().this

我不太确定您要用 this 名称做什么,但我认为它不会起作用。你看过Signals and Slots in PySide了吗?它有一个很好的描述。我想你只需要这样的东西:

class Load(QtCore.QThread):

    onProgress = QtCore.Signal(int)

    def __init__(self, parent):
        QtCore.QThread.__init__(self, parent)
        self.parent = parent

    def run(self):
        '''
        '''
        stacks = []
        count = 100
        for i in range(count):
            # do something ... 
            self.onProgress.emit(count)