[PyQt] Segmentation Fault(coredump) QFileSystemModel, QSortFilterProxyModel, QTreeView

Jean Dalmayrac jean_dalmayrac at yahoo.fr
Thu Dec 2 17:37:33 GMT 2010


Hi All,
I'm having segmentation fault crash while using QFileSystemModel and 
QSortFilterProxyModel.
I'm trying to do a little files manager that will latter fit into a bigger 
application.

Everything is running normally, but after a number (undefined) of clicks on my 
QTreeView to open folders, my  files manager crashes with the following message: 

Segmentation Fault (coredump)
If I directly connect my QFileSystemModel to my QTreeView, the problem no longer 

appears.
The code below is a very lightweight version of my code but it reproduces the 
same problem.
For information, i'm using:
Python 2.4.2
PyQt 4.4.2
Qt 4.5.0
SunOs 5.8

Thanks for you help

Jean

#=======================================================
from PyQt4 import QtGui, QtCore
import sys

class Proxii(QtGui.QSortFilterProxyModel):
    def __init__(self, parent):
        QtGui.QSortFilterProxyModel.__init__(self, parent)
        
    def hasChildren(self, oModelIndex):
        oSourceIndex = self.mapToSource(oModelIndex)
        return self.sourceModel().hasChildren(oSourceIndex)
    
    def canFetchMore(self, oModelIndex):
        oSourceIndex = self.mapToSource(oModelIndex)
        return self.sourceModel().canFetchMore(oSourceIndex)
    
    def fetchMore(self, oModelIndex):
        oSourceIndex = self.mapToSource(oModelIndex)
        return self.sourceModel().fetchMore(oSourceIndex)
#=======================================================
class testExplo(QtCore.QObject):
    def __init__(self):
        QtCore.QObject.__init__(self)
        
        self.myTreeView = QtGui.QTreeView()
        self.myProxy = Proxii(self.myTreeView)
        self.myModel = QtGui.QFileSystemModel(self.myTreeView)

        #-- Model
        self.myModel.setRootPath("/home/")
        #-- Proxi
        self.myProxy.setSourceModel(self.myModel)
        #-- treeview
        self.myTreeView.setModel(self.myProxy)
        
        rootModelIndex = self.myModel.index("/home/")
        rootProxyIndex = self.myProxy.mapFromSource(rootModelIndex)
        self.myTreeView.setRootIndex(rootProxyIndex)

        self.myTreeView.show()
#=======================================================
app = QtGui.QApplication(sys.argv)
myExplo = testExplo()
end = app.exec_()

#=======================================================



      


More information about the PyQt mailing list