[Qt-interest] dataChanged() SIGNAL in proxy models

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Thu Jul 1 10:13:23 CEST 2010


Does the default implementation of QAbstractProxyModel handle the
dataChanged() from the source model?
If no, is it the sub-class's responsibility to generate a
dataChanged() SIGNAL? The proxy models doc does not mention anything
on this.

I have a QStringListModel on which I have applied my proxy model to
return the data in a tabular manner (rows/cols).

Initially I thought that the signal will be handled by
QAbstractProxyModel class. But that did not work.
So I though of emitting the signal on my own, whenever the same signal
is emitted by the source model (who's data is being proxied).

<snip>
...
void setSourceModel(QAbstractItemModel *sourceModel)
{
    QAbstractProxyModel::setSourceModel(sourceModel);

    connect(sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
            this, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
}
...
</snip>

This should work, right? But it doesn't.

Instead of directly linking a SIGNAL to another SIGNAL, I even made it
go through a SLOT which emits the dataChanged() signal just to see if
the signal was being emitted by the source model or not. The signal
was emitted but somehow the view did not react to it.

If I directly attach the QStringListModel to a QListView widget,
things obviously work (i.e the view reacts to changes to the data in
the model).

Do see any problem in the above approach?

Thanks,
-mandeep



More information about the Qt-interest-old mailing list