PDA

View Full Version : QAbstractProxyModel not getting notified when rows are inserted or removed.



snydesc
28th September 2012, 16:37
I have tableview with a custom model along with a tree that has a proxy model.
the proxyModel source model is set to the custom tableview's model.

The table and tree both display data correctly upon creation.
The problem is when I add or remove rows.
The table gets updated correctly but the tree does not.

Is there a reason why the proxy model does not get notified when rows are being inserted/removed?

wysota
28th September 2012, 16:52
Did you connect to appropriate signals in the source model to get updates?

snydesc
28th September 2012, 17:54
I assume so In the source model I emit dataChanged in setData. I also call beginInsertRows()/endInsertRows() when inserting and beginRemoveRows()/endRemoveRows() when removing.

In the proxy model I do not connect to any signals as I thought by doing what I mentioned above would handle that for me.

Added after 36 minutes:

I attached the rowsInserted() signal to a slot within the proxy model and it now updates correctly.

The next problem I am having is that if I have expanded children on the tree they collapse when the row is inserted.

wysota
28th September 2012, 18:02
The next problem I am having is that if I have expanded children on the tree they collapse when the row is inserted.

It seems like something is emitting modelReset().

snydesc
28th September 2012, 18:19
Fixed it :) I was passing in the start and end rows that got returned from the rowsInserted signal as the inserPosition and numberOfRows paramaters for insertRows() which confused the view.