Created
September 16, 2014 11:18
-
-
Save jbmohler/861eb9e16b209cb938ff to your computer and use it in GitHub Desktop.
QItemSelectionModel crash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PySide import QtCore, QtGui | |
class MyWindow(QtGui.QDialog): | |
def __init__(self, parent=None): | |
super(MyWindow, self).__init__(parent) | |
self.model = QtGui.QStringListModel(['sam', 'sally', 'jack'], self) | |
self.v = QtGui.QListView() | |
self.v.setModel(self.model) | |
# OPTION 1: It seems to me that this code should be sufficient | |
# with-out any longer lasting python reference to the | |
# QItemSelectionModel. It crashes immediately in my PySide 1.2.2. | |
#self.v.selectionModel().currentChanged.connect(self.print_sel) | |
# OPTION 2: This works in this context to hold a reference only for | |
# the duration of this scope block. | |
selmodel = self.v.selectionModel() | |
selmodel.currentChanged.connect(self.print_sel) | |
# OPTION 3: I think in some cases I've had to hold a reference in the | |
# enclosing widget parent like this to avoid a crash at window close. | |
#self.selmodel = self.v.selectionModel() | |
#self.selmodel.currentChanged.connect(self.print_sel) | |
# END OPTIONS illustrating QItemSelectionModel issues | |
self.layout = QtGui.QVBoxLayout(self) | |
self.layout.addWidget(self.v) | |
def print_sel(self, *args): | |
print args | |
app = QtGui.QApplication([]) | |
w = MyWindow() | |
w.show() | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment