Results 1 to 2 of 2

Thread: QStringList sort "ABC 200" "ABC 90"

  1. #1
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default QStringList sort "ABC 200" "ABC 90"

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QStringList sort "ABC 200" "ABC 90"

    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,
    _

Similar Threads

  1. Replies: 1
    Last Post: 20th November 2015, 11:02
  2. QSqlError("", "Parameter count mismatch", "")
    By Alberto7 in forum Newbie
    Replies: 2
    Last Post: 9th October 2015, 23:09
  3. Replies: 3
    Last Post: 16th March 2015, 08:31
  4. Replies: 1
    Last Post: 3rd December 2013, 03:19
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.