Results 1 to 6 of 6

Thread: QDir - Entrylist, sort

  1. #1
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Post QDir - Entrylist, sort

    I have file name like

    test1.tcl
    test2.tcl
    test3.tcl
    test10.tcl
    test100.tcl

    when i am taking the ertrylist it is giviving in the order as follows:

    test1.tcl
    test10.tcl
    test100.tcl
    test2.tcl
    test3.tcl

    but i want in the order of
    test1.tcl
    test2.tcl
    test3.tcl
    test10.tcl
    test100.tcl

    I used Qdir::unsort , but it not givng the order of entrylist as i want. How can i do this.

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QDir - Entrylist, sort

    You can override QDirModel::sort and provide your own sorting

  3. #3
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDir - Entrylist, sort

    I am a beginner in Qt,
    can you please tell me how can i override Qdir::sort ?
    Please give one example.

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDir - Entrylist, sort

    The problem is that you are comparing text strings, and so test1, test10 & test100 will always be less than test2. What you need to do is seperate the text and numeric portions and do your own custom sort.

    To override QDir::Sort, just subclass QDir and override the default implementation of sort by writing your own.

  5. #5
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: QDir - Entrylist, sort

    Can you please send me the algorithem for separating numeric and text and sorting them as 1, 2, 3,10.
    If i am using sort algorithem then it is sorting as 1,10,2,3.
    Please help me.

  6. #6
    Join Date
    May 2009
    Posts
    94
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QDir - Entrylist, sort

    I separated numeric and text part, can you please tell how can i do sort that it will arrange as
    1
    2
    3
    10

Similar Threads

  1. QDir entryList performing slowly
    By bunjee in forum Qt Programming
    Replies: 3
    Last Post: 8th October 2009, 16:21
  2. QDir::entryList() on linux
    By JeanC in forum Qt Programming
    Replies: 3
    Last Post: 3rd March 2008, 13:46
  3. qdir and entrylist
    By mattia in forum Newbie
    Replies: 1
    Last Post: 28th November 2007, 10:13
  4. Is it me or QDir?
    By Morea in forum Qt Programming
    Replies: 1
    Last Post: 29th June 2007, 23:06
  5. Qt4: QDir::entryList bug in windows when listing network files?
    By Yvon Halbwachs in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2006, 14:22

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.