[PyQt] Simple connect does not work

Mads Ipsen mpi at comxnet.dk
Fri Apr 24 08:20:34 BST 2009


> Hi,
>
> I am puzzled why the connection used in the example below does not work. I
> get the error:
>
> Object::connect: No such slot SpinBox::foo(int)
>
> Example snippet:
>
> import sys
> from PyQt4 import QtCore, QtGui
>
> class SpinBox(QtGui.QSpinBox):
>     def __init__(self, parent=None):
>         QtGui.QSpinBox.__init__(self, parent)
>
>     def foo(self, i):
>         print i
>
> if __name__ == "__main__":
>     app = QtGui.QApplication(sys.argv)
>
>     spin = SpinBox()
>     QtCore.QObject.connect(spin, QtCore.SIGNAL('valueChanged(int)'),
>                            spin, QtCore.SLOT('foo(int)'))
>     spin.show()
>
>     sys.exit(app.exec_())
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>


OK, I need to use a signature (see below). Sorry for bothering you!

class SpinBox(QtGui.QSpinBox):
    def __init__(self, parent=None):
        QtGui.QSpinBox.__init__(self, parent)

    @QtCore.pyqtSignature("int")
    def foo(self, i):
        print i


More information about the PyQt mailing list