Qt how are alphanumeric strings sorted?
-
Hi ,
I have string data stored in a QStringList like this:
@QStringList list;
list << "text-1"
list << "text-2"
list << "text-7"
list << "text-9"
list << "text-10"
list << "text-12"
list << "text-12"
list << "text-20"
list << "text-23"
list << "text-21"
list << "text-5"@
and I am trying to store them in ascending order like this:
@qSort(list.begin(), list.end());
@
The result I expected is :
"text-1"-- "text-2"--"text-5"-- "text-7"-- "text-9"--"text-10"--"text-12"--"text-12"--"text-20"--"text-21"--"text-23"
but I am getting:
"text-10"--"text-1"-- "text-12"--"text-12"--"text-2"--"text-20"--"text-21"--"text-23"--"text-5"-- "text-7"-- "text-9"
Am I asking to much of the qSort algorithm and should I implement my expected results myself or is there an easy way in Qt to achieve this?
Thank you for your time.
-
See this question on SO: "link":http://stackoverflow.com/questions/11933883/sort-filenames-naturally-with-qt. The answer seems to be to use QCollator class.