[PyQt] Issue with pyqtSlot(QModelIndex, QModelIndex)

Sybren A. Stüvel sybren at stuvel.eu
Tue Jul 27 05:12:23 BST 2010


Dear list,

I've just upgraded from PyQt 4.6 (PyQt-Py2.6-gpl-4.6-1.exe) to version
4.7.4 (PyQt-Py2.6-gpl-4.7.4-1.exe), and the upgrade introduced a crash
in my program. I've narrowed it down to this example:

    from PyQt4 import QtCore, QtGui

    class Dialog(QtGui.QDialog):
        def __init__(self, parent=None):
            QtGui.QDialog.__init__(self, parent)

            self.resultsModel = QtGui.QStandardItemModel()
            self.resultsModel.appendRow(QtGui.QStandardItem('Item 1'))
            self.resultsModel.appendRow(QtGui.QStandardItem('Item 2'))
            self.resultsModel.appendRow(QtGui.QStandardItem('Item 3'))

            self.layout = QtGui.QVBoxLayout(self)
            self.resultsView = QtGui.QTreeView(self)
            self.resultsView.setModel(self.resultsModel)

            self.layout.addWidget(self.resultsView)
            
            smodel = self.resultsView.selectionModel()
            smodel.currentChanged.connect(self.on_change)

        @QtCore.pyqtSlot(QtCore.QModelIndex, QtCore.QModelIndex)
        def on_change(self, current, previous):
            print 'Changed from %s to %s' % (previous.row(), current.row())

    app = QtGui.QApplication([])
    win = Dialog()
    win.show()
    app.exec_()

The program crashes with this error:

    Traceback (most recent call last):
      File "qttest.py", line 26, in <module>
        win = Dialog()
      File "qttest.py", line 19, in __init__
        smodel.currentChanged.connect(self.on_change)
    TypeError: on_change() has no overload that is compatible with
    currentChanged(QModelIndex,QModelIndex)

When I remove the @QtCore.pyqtSlot() decorator the code runs just
fine. It's a workaround, but I would prefer a clearner solution, or at
least an understanding as to the cause of the exception.

The exception occurs when running on PyQt 4.7.4, Qt 4.6.2 and Python
2.6 on Windows XP.

The same code runs without error on PyQt 4.7.3, Qt 4.6.3 and Python
2.6 on Ubuntu Linux.

Regards,
-- 
Sybren Stüvel

http://stuvel.eu/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100727/a46a0011/attachment.pgp>


More information about the PyQt mailing list