Connecting QTableView selectionChanged signal produces segfault with PyQt

I have a QTableView in a PyQt application and I want to track when the selection changes. I tried to connect the signal to the slot as follows (using the tip on this page :

self.view.selectionModel().selectionChanged.connect(self.selChanged) 

where the slot to which it is connected is defined as:

 def selChanged(self, selected, deselected): print "Sel changed" 

However, when I load the QMainWindow that the QTableView resides on, I get an immediate segmentation error.

Am I doing something stupid here?

+6
user-interface qt pyqt qtableview
source share
2 answers

This is now fixed, it turned out that I was using an old version of Qt on this machine, which seemed to cause a crash.

The moral of this story is: if your code crashes for no good reason, check all your dependencies (in this case Qt and PyQt) have been updated.

+2
source share

I had a similar problem and the problem was here: PySide: Segfault (?) When using QItemSelectionModel with QListView

Namely, replace:

 self.view.selectionModel().selectionChanged.connect(self.selChanged) 

with two commands:

 selectionModel = self.view.selectionModel() selectionModel.selectionChanged.connect(self.selChanged) 

Not sure why this works, honestly.

+4
source share

All Articles