tags:

views:

87

answers:

2

How can sort QStringListModel?

Thanks a lot.

+4  A: 

By using the sort method.

Patrice Bernassola
The `QStringListModel::sort()` method is not reimplemented from the `QAbstractItemModel::sort()` in Qt version prior to 4.6. You will need Qt 4.6 for the sort method to behave correctly.
Lohrun
+2  A: 

An alternative to the QStringListModel::sort() method is to use the QStringList::sort() method on the string list stored into the model. This approach is not as efficient as using the QStringListModel::sort().

QStringList list = stringListModel->stringList();
list.sort();
stringListModel->setStringList(list);
Lohrun