PDA

View Full Version : SqlTableModel not updating AbstractProxyModel



akiross
12th November 2008, 17:15
Hello!
In my application (qt 4.4.2) I've a QSqlTableModel, which is used as source model for a custom proxy model, which does a little more than filtering (so I can't use filter proxy model).

The table model is source model for a table view while the proxy model is source for a list view.

But, if I add new record to the sqltablemodel, the list view isn't updated and I don't see anything added.
I tried overwriting setSourceModel in my proxy, connecting source's dataChanged(...) signal to a new signal which print a message with qDebug, but this message is never printed, so it seems that dataChanged is never called from a QSqlTableModel.

Is this normal? How can I overcome this updating issue?
Thanks

victor.fernandez
12th November 2008, 17:42
You need either to call QSortFilterProxyModel::invalidateFilter() whenever your model changes or to set the dynamicSortFilter property to true (warning: slow).

akiross
12th November 2008, 18:22
But i'm not using QSortFilterProxyModel! I'm using QAbstractProxyModel... Shall I use SortFilter instead?
It's quite nonsense, since I don't need any of the features it provides (sort and filtering).

caduel
12th November 2008, 20:13
Well, if you do not use those features, they hopefully won't use too much processing power ;-)

The source model does not have to emit dataChanged() if only a new row has been added. That is what rowsInserted() is for.

akiross
13th November 2008, 15:20
Oops! You're so right! I forgot about rowsInserted.
Anyway that was just a test, the problem remains: view isn't updated correctly (both on row insertion and data changing)...


The signals and slots used by the model/view framework ensure that each view is updated appropriately no matter how many proxy models are placed between itself and the source model.

Am I supposed to forward the signals when using abstract proxy models?

caduel
13th November 2008, 15:52
Your proxy has to tell the view all the view needs to know.
So, unless your proxy does not show a row that has been modified or inserted, yes, you will need to forward those signals.

akiross
13th November 2008, 16:43
Ok, thank you :)

caduel
13th November 2008, 16:51
note: you need not only forward the signals, but -depending on what your proxy does- adapt the arguments: maybe you need to adjust the row of a QModelIndex, maybe you need to replace indexes of the source model for ones of your model...)

Let the source of QSortFilterProxyModel inspire you...