oKcerG / SortFilterProxyModel

A nicely exposed QSortFilterProxyModel for QML
MIT License
301 stars 102 forks source link

Crashes when QML debugging is enabled #52

Open timangus opened 6 years ago

timangus commented 6 years ago

One thing I've noticed recently is that (presumably) changes in the QML debugger have started to cause crashes in qqsfpm. It seems that the debugger sometimes ends up (for whatever reason) in calling qqsfpm::data with an invalid index, which ultimately results in sourceModel() returning nullptr, and thus a nullptr de-reference. My fix is as follows, which is probably no bad thing anyway.

QVariant QQmlSortFilterProxyModel::data(const QModelIndex &index, int role) const
{
    if(!index.isValid())
        return {};

    return sourceData(mapToSource(index), role);
}
oKcerG commented 6 years ago

Thanks, I'll look into that

timangus commented 6 years ago

Or perhaps I should be using QAbstractItemModel::checkIndex()!

https://www.kdab.com/new-in-qt-5-11-improvements-to-the-model-view-apis-part-1/