Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt how are alphanumeric strings sorted?
Forum Update on Monday, May 27th 2025

Qt how are alphanumeric strings sorted?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    musimbate
    wrote on 23 Dec 2014, 05:43 last edited by
    #1

    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.

    Why join the navy if you can be a pirate?-Steve Jobs

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 23 Dec 2014, 07:54 last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      0

      1/2

      23 Dec 2014, 05:43

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved