PDA

View Full Version : QStringList sort "ABC 200" "ABC 90"



HappyCoder
2nd January 2017, 11:44
Hello,

i have a QStringList and use the public function sort() to sort my list.

Two entrys of my list are "ABC 200" and "ABC 90" and they are sorted

"ABC 200"
"ABC 90"

but i want this

"ABC 90"
"ABC 200"

How can i achieve that?

Thx
HappyCoder

PS: With "ABC 200" and "ABC 90" is one example, my list contains over 30 entrys and this happens several times.

anda_skoa
2nd January 2017, 12:01
String comparison says that "9" is greater than "2".

If your strings have a patter that includes some text and some number, then you need to provide a "less than" implementation for a generic sorting algorithm that understands these patterns.

E.g. providing a predicate function to qSort() or std::sort()

Cheers,
_