PDA

View Full Version : ProxyModel problem



waynew
14th February 2010, 01:05
I need to relate the view index to the model index for searches in the view.
Based the model index on the database table primary key.
Not sure I understand the proxy model doc, but,
here is what I tried:



QSortFilterProxyModel *proxy = new QSortFilterProxyModel(model);
QModelIndex midx = model->index(id, 0, QModelIndex());
qDebug() << " midx is " << midx;
QModelIndex vidx = proxy->mapFromSource(midx);
qDebug() << " vidx is " << vidx;


midx has the correct value for the row in the model/database.
vidx is -1 The error says index from wrong model passed to mapFromSource.
What's wrong?

Coises
14th February 2010, 06:40
The constructor for QSortFilterProxyModel doesn’t set the source model; it sets the QObject that owns the proxy model. (You can let that default to null if you will delete the proxy model yourself.) You have to use QSortFilterProxyModel::setSourceModel to set the source model.