[PyQt] Issue with pyqtSlot(QModelIndex, QModelIndex)

Phil Thompson phil at riverbankcomputing.com
Tue Jul 27 12:05:34 BST 2010


On Tue, 27 Jul 2010 06:12:23 +0200, Sybren A. Stüvel <sybren at stuvel.eu>
wrote:
> 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.

Should be fixed in tonight's snapshot - a patch is attached if you can't
wait.

As this is a regression I'll make a new PyQt release in a few days - once
I've had confirmation that the fix doesn't cause any other problems.

Thanks for the test case,
Phil
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PyQt.patch
Type: text/x-diff
Size: 2921 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100727/44671071/attachment.patch>


More information about the PyQt mailing list