PDA

View Full Version : What happens if QSortFilterProxyModel has no sourceModel?



nifei
13th May 2009, 05:20
Since QSortFilterProxyModel can be set data, what will happen if


QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel(this);
for( qint32 i = 0; i < 5; i++)
{
for( qint32 j = 0; j < 5; j++)
{
QModelIndex index(i, j);
proxyModel->setData(QVariant(), index);
}
}
QTableView *tableView = new QTableView(this);
tableView->setModel(proxyModel);
tableView->setSortingEnabled(true);

aamer4yu
13th May 2009, 06:35
I guess nothing will appear on view...
If you have tried it, you can tell us the answer :P

talk2amulya
13th May 2009, 08:22
of course it wont show anything, first of all, your index would always be invalid like this, secondly, even if setData is called, it would be called of QAbstractItemModel!!
no use of this whole code..

nifei
14th May 2009, 03:58
I guess nothing will appear on view...
If you have tried it, you can tell us the answer :P

u'r right , nothing shows.

nifei
14th May 2009, 04:05
of course it wont show anything, first of all, your index would always be invalid like this, secondly, even if setData is called, it would be called of QAbstractItemModel!!
no use of this whole code..

yes. then i tried to insert rows and columns to the proxy model and called setData(), some items appears and some does not, and there're repeat ones, i think that is because i set the proxy model sort dynamically, and set data to exiting items. anyway, source model is easier to handle, especially use a QStandardItemModel.

wysota
14th May 2009, 10:06
I think that's because you are using the proxy in a way it was not meant to be used. Attach a source model to it.