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 Updated to NodeBB v4.3 + New Features

Qt how are alphanumeric strings sorted?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.2k Views 1 Watching
  • 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.
  • musimbateM Offline
    musimbateM Offline
    musimbate
    wrote on 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
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on 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

      • Login

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