Hi,

I'm having issue with what I believe to be an hello world example.

I'm trying to implement a QSortFilterProxyModel to filter a Table which takes its data from a subclass of QAbstractTableModel.

The problem that I have is that whenever I'm selecting a cell and then start filtering, I'm having a segmentation fault from the python interpreter. The stacktrace guides me to mapFromSource in a QT shared object. Sometime I see the following error in the terminal in which I'm running my QtApplication

index from wrong model passed to mapFromSource

I've checked the Qt Documentation and I'm following the recommendation when subclassing QAbstractTableModel and QSortFilterProxyModel.

Here is my implementation of my QAbstractTableModel and QSortFilterProxyModel

Qt Code:
  1. class MyTableModel(QAbstractTableModel):
  2. def __init__(self, datain, parent=None, *args):
  3. QAbstractTableModel.__init__(self, parent, *args)
  4. self.arraydata = datain
  5.  
  6. def rowCount(self, parent):
  7. return len(self.arraydata)
  8.  
  9. def columnCount(self, parent):
  10. return BankRecord.getMaxIdx()
  11.  
  12. def data(self, index, role):
  13. if not index.isValid():
  14. return QVariant()
  15. elif role != Qt.DisplayRole:
  16. return QVariant()
  17. return QVariant(self.arraydata[index.row()].getIdxData(index.column()))
  18.  
  19. def headerData(self, section, orientation, role):
  20. if orientation == QtCore.Qt.Vertical:
  21. return QVariant()
  22. if role != Qt.DisplayRole:
  23. return QVariant()
  24. return QVariant(BankRecord.getIdxHeaderData(section))
  25.  
  26. class RecordFilter(QSortFilterProxyModel):
  27. def __init__(self, parent):
  28. super(RecordFilter,self).__init__(parent)
  29. self.filterHeader = None
  30.  
  31. def setFilterHeader(self, filterHeader):
  32. self.filterHeader = filterHeader
  33.  
  34. def filterAcceptsRow(self, source_row, source_parent):
  35. sourceModel = self.sourceModel()
  36. if not self.filterHeader:
  37. return False
  38. for i in range(BankRecord.getMaxIdx()):
  39. idx = sourceModel.index(source_row, i, source_parent)
  40. dataString = sourceModel.data(idx, Qt.DisplayRole).value().lower()
  41. filterText = self.filterHeader.filterText(i).lower()
  42. if len(filterText) > 0 and not dataString.find(filterText) >= 0:
  43. return False
  44. return True
To copy to clipboard, switch view to plain text mode 

If you are curious, the rest of the source code of my application is available on Github (https://github.com/lcarlier/BankRecordsAnalyzer)
You can easily test the problem because there is a record directly inserted into the table. Then you must play a bit with the filter (adding removing characters in filter fields) and the application is eventually crashing.

Has anybody an idea what my problem is?

Kind regards,

Laurent