PDA

View Full Version : QListView SelectionModel selectionChanged Crash



chouqud
23rd April 2014, 15:26
In PySide I have the following MainWindow definition:



class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)

self.view = QtGui.QListView(self)
self.model = QtGui.QStandardItemModel()
for i in range(10):
self.model.setItem(i, QtGui.QStandardItem("Item {0}".format(i)))

self.view.setModel(self.model)
self.view.selectionModel().selectionChanged.connec t(self._selectionChanged)

self.setCentralWidget(self.view)

def _selectionChanged(self,selected, deselected):
pass


When I try and connect the selectionChanged signal I crash python. It's the same as this SO post (http://stackoverflow.com/questions/19211430/pyside-segfault-when-using-qitemselectionmodel-with-qlistview) and the workaround suggestion of keeping the selection model around seems to work.



self.viewselectionModel = self.view.selectionModel()
self.viewselectionModel.selectionChanged.connect(s elf._selectionChanged)


But is this safe? And is this an official bug in PySide? I could not find anything in the bug report database (https://bugreports.qt-project.org).

_chouqud_