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. Sort QFileInfoList to handle file names that end with numbers
Forum Updated to NodeBB v4.3 + New Features

Sort QFileInfoList to handle file names that end with numbers

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.3k 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.
  • O Offline
    O Offline
    oracle3001
    wrote on last edited by
    #1

    Currently if you have files that end in numbers, a QFileInfoList list created by calling dir.entryInfoList() appears in the following order,

    test_1.txt,
    test_10.txt,
    test_11.txt, etc

    I want to sort a QFileInfoList so that it is number aware i.e the list is as follows,

    test_1.txt
    test_2.txt
    .....
    test_10.txt
    test_11.txt

    Any help much appreciated.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Francknos
      wrote on last edited by
      #2

      Take Name of file, split with each name with "_",
      Take the second for each (1=> test 2=>1.txt)
      then split this with "." now you have 1 2 3 4 5 6 7 8 9 10 11 ...

      1 Reply Last reply
      0
      • O Offline
        O Offline
        oracle3001
        wrote on last edited by
        #3

        If people are interested....I did some more searching and thinking and the way to do this is to use a qSort with a custom struct that enables a "Natural Sort",

        http://stackoverflow.com/questions/11933883/sort-filenames-naturally-with-qt

        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