我一直在尝试使控制器能够处理信号(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_()
试图按照以下两个页面中的示例进行操作:
答案 0 :(得分:0)
一个发出信号的对象是一个对象,在您的助手中它不是对象,而是类的名称,因此解决方案是创建一个对象。对于另外的str
和tuple
是表示数据类型的保留字,在pyqtSignal()
的情况下,由于pyqtSignal()需要将其处理的数据类型作为参数,因此其用法是正确的。因为您重叠了他的名字,所以请勿在{{1}}中将其用作参数。
Emt()