Reputation: 41
By designing a GUI for my python script which works with PySerial for implementing some serial interface functions I want to have shown up some parameters reading out a source. So this GUI for example has to show the actual voltage which is represented by the parameter volt_act. I thought that I can connect the QLCDNumber lcdVoltage with the following code:
self.connect(self, QtCore.SIGNAL("selfVoltage"), self.lcdVoltage, QtCore.SLOT("display(int)"))
And at the point I want to read the voltage I emit the parameter:
self.emit(QtCore.SIGNAL("selfVoltage"), volt_act)
But that doesn't work. How can I correctly implement a QLCDNumber where the parameter is updated in real-time when I emit it?
Upvotes: 1
Views: 1314
Reputation: 36715
From docs:
Short-circuit signals do not have a list of arguments or the surrounding parentheses.
Short-circuit signals may only be connected to slots that have been implemented in Python. They cannot be connected to Qt slots or the Python callables that wrap Qt slots.
You need to declare the variable type explicitly, if you intend to use Qt slots:
self.connect(self, QtCore.SIGNAL("selfVoltage(int)"), self.lcdVoltage, QtCore.SLOT("display(int)"))
and
self.emit(QtCore.SIGNAL("selfVoltage(int)"), volt_act)
But, I'd really suggest you to use the new style signals.
First, you'd define a signal as class variable:
voltage = QtCore.pyqtSignal(int)
then connect it:
self.voltage.connect(self.lcdVoltage.display)
and finally, you'd emit:
self.voltage.emit(volt_act)
Upvotes: 2