Sorting QStringList using qSort
I am suing QStringList to store the data. QStringList having the following item.
I am using qSort() to sort the list as follows.
qSort(list.begin(), list.end(), caseInsensitiveLessThan);
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
return s1.toLower() < s2.toLower();
But it give the sortine order as "user1"<<User10"<<"User2"<<"user6"<<"User7".
But i want the following order after sorting.
Can any one of you give solution to solve the problem its very helpful.
Thanks in advance
There is no one-liner for that. You need a better comparison function called "natural comparison" i.e. not how a computer understands order but how humans do.
Here's a nice implementation of such algorithm with code for various languages: http://www.davekoelle.com/alphanum.html
You should be able to easily modify it to fit with qSort.