[PyQt] Segfault when activating items in a view, more info

peter at lohmanders.se peter at lohmanders.se
Mon Aug 9 11:51:48 BST 2010


Hi Andreas!

Yes, the model isn't properly implemented, still not sure why I'm getting a 
segfault rather than infinite loop. Might be some internal stack overflow?

Anyway, thanks for your reply! I didn't even consider it would would try 
using children indices since a table model doesn't/shouldn't have them.

Thanks a bunch!
/Peter

On 2010-08-09 (Mon) 12:20, Andreas Pakulat wrote:
> On 09.08.10 12:06:57, Hans-Peter Jansen wrote:
> > Hi Peter,
> > 
> > while not of big help, here are a few more details and the backtrace.
> > 
> > Qt 4.6.3, sip 4.10.5, PyQt4 4.7.4.
> > 
> > On Monday 09 August 2010, 09:42:05 peter at lohmanders.se wrote:
> > > Yes, the connect signal had the wrong signature, but that doesn't matter.
> > > I do not get a warning when trying to connect invalid signals, but
> > > even if I have no activated-signal connected, the darn thing still
> > > segfaults when I double click any cell.
> > 
> > Well, even with a correct signal, this crashes (after executing the signal
> > handler):
> > 
> > import sys
> > from PyQt4 import QtGui, QtCore
> > 
> > class TestModel(QtCore.QAbstractTableModel):
> > 
> >     def headerData(self, section, orientation, role =
> >                    QtCore.Qt.DisplayRole):
> >         return QtCore.QVariant("a")
> > 
> >     def data(self, index, role = QtCore.Qt.DisplayRole):
> >         if (role == QtCore.Qt.DisplayRole
> >             and index.isValid()
> >             and 0 <= index.row() < 2
> >             and 0 <= index.column() < 2):
> >             return QtCore.QVariant("t")
> >         return QtCore.QVariant()
> > 
> >     def columnCount(self, index):
> >         return 2
> > 
> >     def rowCount(self, index):
> >         return 2
> 
> If you use this model on a treeview you'll probably end up in an infinite
> tree size. The reason is that you're returning a child-count of 2 for each
> and every index (and the treeview is going to ask for the row-count of each
> toplevel entry). Try to add a check for index.isValid() and only return 2
> if its not a valid index.
> 
> Andreas
> 
> -- 
> Cheer Up!  Things are getting worse at a slower rate.
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt


More information about the PyQt mailing list