AttributeError: 'PyQt4.QtCore.pyqtBoundSignal' object has no attribute 'Emt'

AttributeError: 'PyQt4.QtCore.pyqtBoundSignal' object has no attribute 'Emt'

我一直在尝试让控制器处理信号 (pyqtSignal),但在与 GUI 交互时收到此消息:

Traceback (most recent call last):
  File "main_signals.py", line 102, in <module>
    helper.Sinal.Emt.connect(PID.Imprime, QtCore.Qt.QueuedConnection)
AttributeError: 'PyQt4.QtCore.pyqtBoundSignal' object has no attribute 'Emt'

有人能告诉我我哪里做错了吗,这是代码的精简版 (main_signals.py):

# Import 3rd party libraries
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import QObject, pyqtSignal
import time
import pyqtgraph

# Import python standard modules
import sys 

# This file holds the MainWindow
import Plotter 

# Variables
T = [0]
R = [0]

# Disregard this function
def ReadChannel(channel):

# -----------------------------------------------------------------
class Ctrldr(QtGui.QMainWindow, Plotter.Ui_MainWindow):

    def __init__(self):
        super(self.__class__, self).__init__()
        self.setupUi(self)
        self.QOutput.clicked.connect(self.Calculo)        

    # Plotting
    @QtCore.pyqtSlot(str, tuple)
    def Imprime(self, name, ptm):
        global T, R, W
        x, y = ptm
        R.append(y)
        self.graphicsView.plotItem.plot(T, R, pen='b')

    # Calculations
    def Calculo(self):
        global T

        t = time.clock()
        T.append(t)

        Read = ReadChannel(0)
        Helper.Sinal.emit("Sensor", (t, Read))
        Read = str(Read)
        self.QResult.setText(Read)

# -----------------------------------------------------------------
class Helper(QtCore.QObject):

    Sinal = QtCore.pyqtSignal(str, tuple)

    def __init__(self):
        super(self.__class__, self).__init__()

    def Emt(self, str, tuple):
        self.Sinal.emit(str, tuple) 

# -----------------------------------------------------------------
if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    PID = Ctrldr()

    helper = Helper()
    helper.Sinal.connect(PID.Imprime)

    PID.show()
    app.exec_()

尝试按照以下 2 页中的示例进行操作:

发出信号的是一个对象,在你的Helper中它不是一个对象,而是一个class的名字,所以解决办法是创建一个对象。对于另一个 strtuple 是指示数据类型的保留字,在 pyqtSignal() 的情况下,它的使用是正确的,因为 pyqtSignal () 需要将其处理的数据类型作为参数,但是不要将它用作 Emt() 中的参数,因为你重叠了他的名字。

# Import 3rd party libraries
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import QObject, pyqtSignal
import time
import pyqtgraph

# Import python standard modules
import sys 

# This file holds the MainWindow
import Plotter 

# Variables
T = [0]
R = [0]

# Disregard this function
def ReadChannel(channel):
    # some process
    return channel

# -----------------------------------------------------------------

# -----------------------------------------------------------------
class Helper(QtCore.QObject):
    Sinal = QtCore.pyqtSignal(str, tuple)
    def Emt(self, arg1, arg2):
        self.Sinal.emit(arg1, arg2) 


class Ctrldr(QtGui.QMainWindow, Plotter.Ui_MainWindow):
    def __init__(self):
        super(self.__class__, self).__init__()
        self.setupUi(self)
        self.QOutput.clicked.connect(self.Calculo)
        self.helper = Helper(self) # <--- object

    # Plotting
    @QtCore.pyqtSlot(str, tuple)
    def Imprime(self, name, ptm):
        global T, R, W
        x, y = ptm
        R.append(y)
        self.graphicsView.plotItem.plot(T, R, pen='b')

    # Calculations
    def Calculo(self):
        global T

        t = time.clock()
        T.append(t)

        Read = ReadChannel(0)
        self.helper.Sinal.emit("Sensor", (t, Read))
        Read = str(Read)
        self.QResult.setText(Read)


# -----------------------------------------------------------------
if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    PID = Ctrldr()

    helper = Helper()
    helper.Sinal.connect(PID.Imprime)

    PID.show()
    app.exec_()