Important: Please read the Qt Code of Conduct -

Subclassed QSortFilterProxyModel doesn't forward dataChanged signal

  • Hi,
    I've got my (QAbstractTableModel) model that occasionally emits the dataChanged signal. Then I've got a (QTableView) view which has a reimplemented dataChanged slot containing
    @qDebug() << "Yay!";@

    If I directly set the model to the view, "Yay!" is printed as expected, so that seems to work fine.

    Between model and view, I actually place a QSortFilterProxyModel subclass. The only thing this subclass reimplements is:
    @::headerData(int section, Qt::Orientation orientation, int role) const
    ::columnCount(const QModelIndex &parent) const
    ::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const@

    And these three (apart from being very simple) seem to work fine, since column removing/adding/sorting etc. works as expected.

    But "Yay!" never happens.
    I've checked the QSortFilterProxyModel source code and it seems to me, the dataChanged is handled, at least they connect it to "_q_sourceDataChanged" which does some fancy source-proxy-mapping.

    Any hints what I'm doing wrong would be nice.

  • Ha!
    It's always the things that "are correct for sure" that bite you!
    Turns out just printing "Yey!" wasn't so smart, the parameters I passed to dataChanged were wrong and so the filter proxy didn't let the signal through.

    I emitted like this:
    @emit dataChanged(index(id, 0), index(id, columnCount()));@
    When I should have emitted
    @emit dataChanged(index(id, 0), index(id, columnCount()-1));@
    Obviously ;)
    Sadly this "column out of bounds" situation doesn't produce any qDebug output in the model or view, but is silently turned into column id -1 and row id 0 (!). Sneaky.

Log in to reply