Note that there are some explanatory texts on larger screens.

plurals
  1. POPyQt: No such slot
    primarykey
    data
    text
    <p>I am starting to learn Qt4 and Python, following along some tutorial i found on the interwebs. I have the following two files:</p> <p>lcdrange.py:</p> <pre><code>from PyQt4 import QtGui, QtCore class LCDRange(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) lcd = QtGui.QLCDNumber(2) self.slider = QtGui.QSlider() self.slider.setRange(0,99) self.slider.setValue(0) self.connect(self.slider, QtCore.SIGNAL('valueChanged(int)'), lcd, QtCore.SLOT('display(int)')) self.connect(self.slider, QtCore.SIGNAL('valueChanged(int)'), self, QtCore.SIGNAL('valueChanged(int)')) layout = QtGui.QVBoxLayout() layout.addWidget(lcd) layout.addWidget(self.slider) self.setLayout(layout) def value(self): self.slider.value() def setValue(self,value): self.slider.setValue(value) </code></pre> <p>main.py:</p> <pre><code>import sys from PyQt4 import QtGui, QtCore from lcdrange import LCDRange class MyWidget(QtGui.QWidget): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) quit = QtGui.QPushButton('Quit') quit.setFont(QtGui.QFont('Times', 18, QtGui.QFont.Bold)) self.connect(quit, QtCore.SIGNAL('clicked()'), QtGui.qApp, QtCore.SLOT('quit()')) grid = QtGui.QGridLayout() previousRange = None for row in range(0,3): for column in range(0,3): lcdRange = LCDRange() grid.addWidget(lcdRange, row, column) if not previousRange == None: self.connect(lcdRange, QtCore.SIGNAL('valueChanged(int)'), previousRange, QtCore.SLOT('setValue(int)')) previousRange = lcdRange layout = QtGui.QVBoxLayout() layout.addWidget(quit) layout.addLayout(grid) self.setLayout(layout) app = QtGui.QApplication(sys.argv) widget = MyWidget() widget.show() sys.exit(app.exec_()) </code></pre> <p>When i run this i get the following errors:</p> <pre><code>Object::connect: No such slot LCDRange::setValue(int) Object::connect: No such slot LCDRange::setValue(int) Object::connect: No such slot LCDRange::setValue(int) Object::connect: No such slot LCDRange::setValue(int) Object::connect: No such slot LCDRange::setValue(int) Object::connect: No such slot LCDRange::setValue(int) Object::connect: No such slot LCDRange::setValue(int) Object::connect: No such slot LCDRange::setValue(int) </code></pre> <p>I've read that PyQt slots are nothing more than methods, which i have defined, so what am i doing wrong?</p> <p>I am also learning Qt4 with Ruby which is where this code originates from, i translated it from Ruby to Python. In the Ruby version the LCDRange class is defined as this:</p> <pre><code>class LCDRange &lt; Qt::Widget signals 'valueChanged(int)' slots 'setValue(int)' def initialize(parent = nil) ... </code></pre> <p>So my guess was that i have to somehow declare the existence of the custom slot?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload