QSortFilterProxyModel mapToSource causes segfault
-
My tableView hides rows that are not in a cache held by the data model, and in order to hide the row. My TableView connects to a QSortFilterProxyModel which connects to a QAbstractTableModel. The function is as follows:
bool CompanySortFilterProxyModel::isRowInCache(const int rowNumber) const { QModelIndex sourceModelIndex = mapToSource(createIndex(rowNumber,0)); // Crash on this line return m_dataModel->isRowInCache(sourceModelIndex.row()); }
I pass a rowNumber to the above function (in this case row 0), and my TableView holds 16 rows, my data model holds 100+ rows. The above function must translate the QSFPM row number to a QATM row number, so I call the mapToSource function. But the mapToSource function segfaults in the ancestor's index_to_iterator function.
What am I doing wrong? With qDebug I confirmed the sourceModelIndex is valid. The QSFPM code which segfaults is below.
inline QHash<QModelIndex, Mapping *>::const_iterator index_to_iterator( const QModelIndex &proxy_index) const { Q_ASSERT(proxy_index.isValid()); Q_ASSERT(proxy_index.model() == q_func()); const void *p = proxy_index.internalPointer(); Q_ASSERT(p); QHash<QModelIndex, Mapping *>::const_iterator it = static_cast<const Mapping*>(p)->map_iter; // SEGFAULT HERE Q_ASSERT(it != source_index_mapping.constEnd()); Q_ASSERT(it.value()); return it; }
-
My tableView hides rows that are not in a cache held by the data model, and in order to hide the row. My TableView connects to a QSortFilterProxyModel which connects to a QAbstractTableModel. The function is as follows:
bool CompanySortFilterProxyModel::isRowInCache(const int rowNumber) const { QModelIndex sourceModelIndex = mapToSource(createIndex(rowNumber,0)); // Crash on this line return m_dataModel->isRowInCache(sourceModelIndex.row()); }
I pass a rowNumber to the above function (in this case row 0), and my TableView holds 16 rows, my data model holds 100+ rows. The above function must translate the QSFPM row number to a QATM row number, so I call the mapToSource function. But the mapToSource function segfaults in the ancestor's index_to_iterator function.
What am I doing wrong? With qDebug I confirmed the sourceModelIndex is valid. The QSFPM code which segfaults is below.
inline QHash<QModelIndex, Mapping *>::const_iterator index_to_iterator( const QModelIndex &proxy_index) const { Q_ASSERT(proxy_index.isValid()); Q_ASSERT(proxy_index.model() == q_func()); const void *p = proxy_index.internalPointer(); Q_ASSERT(p); QHash<QModelIndex, Mapping *>::const_iterator it = static_cast<const Mapping*>(p)->map_iter; // SEGFAULT HERE Q_ASSERT(it != source_index_mapping.constEnd()); Q_ASSERT(it.value()); return it; }