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

Tony Rietwyk tony.rietwyk at rightsoft.com.au
Thu Jul 1 10:46:14 CEST 2010


Hi Mandeep, 

I haven't used proxy models, but I'm surprised that the dataChanged signal
isn't mapped for you.  Connecting the source signal to the proxy's signal
won't work, since the source index parameter refers to the source model,
which the table view won't recognise.  When you connected to a slot, did you
map the source index to the proxy's rows & columns?  

Hope that helps, 

Tony


> -----Original Message-----
> 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