Results 1 to 4 of 4

Thread: Sort Qlist and return index

  1. #1
    Join Date
    Dec 2010
    Posts
    55
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Sort Qlist and return index

    I have a qlist of floats that I would like to sort. However I am looking for a list of the sorted indices.
    I could have a qhash of index and float pairs, but I don't know how to sort a qhash on the value.
    Running:
    RHEL 5.4
    Python 2.7.2
    Qt 4.7.4
    SIP 4.7.8
    PyQt 4.7

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sort Qlist and return index

    So you don't want to sort the original list but rather have a new list that containes a list of indexes of the original list that would make it a sorted list, yes?

    I think the easiest way is to use a functor that takes the original list as a parameter as a custom LessThan operator for qSort() that would operate on a list containing indexes of the original list (so starting with a sorted list of 0..(originalList.count()-1)).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2010
    Posts
    55
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Sort Qlist and return index

    I was hoping there was an easier way than that like how you can sort columns on a table.
    Are there any examples of howto create a custom LessThan to pass to qSort?
    Running:
    RHEL 5.4
    Python 2.7.2
    Qt 4.7.4
    SIP 4.7.8
    PyQt 4.7

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sort Qlist and return index

    Quote Originally Posted by enricong View Post
    I was hoping there was an easier way than that
    It is quite easy.

    like how you can sort columns on a table.
    And how do you do that?

    Are there any examples of howto create a custom LessThan to pass to qSort?
    I'm sure there are some in the docs. And here is one that uses a functor:
    http://qt-project.org/forums/viewthread/4978 (which of course does something completely different from what you want).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Sort QList of pointers
    By giantdragon in forum Newbie
    Replies: 5
    Last Post: 1st June 2011, 19:53
  2. I Want to sort QList<QMap<QString , qreal > >
    By amiref in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2011, 13:33
  3. How to sort a Qlist AND get a sort key?
    By agerlach in forum Qt Programming
    Replies: 3
    Last Post: 26th July 2010, 18:44
  4. Return value to QList
    By lyucs in forum Newbie
    Replies: 7
    Last Post: 16th October 2009, 02:31
  5. QList index out of range problem
    By MarkoSan in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2008, 08:40

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
  •  
Qt is a trademark of The Qt Company.