PDA

View Full Version : Sorting on a model with multiple strings in items



abk883
6th May 2010, 14:21
Hi

I have a model where for each item I have Multiple Text Strings for display. Sortingdoesn't seem to work when I have multiple Strings. But works when i have a single String.

Here is my Code:
:rolleyes:
QStringList data;
QStandardItem *item = new QStandardItem();
data.clear();
data << "ABC" << "DEF" ;
item->setData(QVariant(data), Qt::DisplayRole);
MyStandardModel->insertRow(0);
MyStandardModel->setItem(0,item);
StandardModel->sort(0,Qt::AscendingOrder);

So here Sorting doesn't work on Model, but if I change:
data << "ABC" << "DEF" ; to data << "ABC" ;
Sorting Works.

Same is the Case while Filtering using Sort FilterproxyModel Applied on it.

Could someone please tell me where am I going wrong or the changes I need to make to sort()

Thanks

chandan
7th May 2010, 16:01
Subclass QAbstractListModel class. And than re-implement

virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex &index, int role) const;

It will make your work easier.

Hope this will help.