Results 1 to 8 of 8

Thread: sorting QList<double>

  1. #1
    Join Date
    Aug 2009
    Posts
    122
    Thanks
    74
    Qt products
    Qt4
    Platforms
    Windows

    Question sorting QList<double>

    How to sort QList<double>. Unfortunately sort() is not a member of this class. What would be the best way to do this sort? Is this the best way:

    Qt Code:
    1. qSort(mylist.begin() , mylist.end());
    To copy to clipboard, switch view to plain text mode 
    Last edited by timmu; 24th August 2012 at 14:08.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: sorting QList<double>

    It's the only way to sort lists.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: sorting QList<double>

    QList is not the Qt way for std::list, i mean that it's not a linked list, read more here.

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: sorting QList<double>

    Quote Originally Posted by spirit View Post
    It's the only way to sort lists.
    QList has random access. You can therefore use any of these, I believe.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: sorting QList<double>

    Quote Originally Posted by amleto View Post
    QList has random access. You can therefore use any of these, I believe.
    Then is not going to be Qt-way sorting.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #6
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: sorting QList<double>

    so?

    1234567890
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  7. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: sorting QList<double>

    Quote Originally Posted by amleto View Post
    so?

    1234567890
    There is nothing "so". You blame people to not start posts which don't have anything w Qt, but here you suggest to use the way which doesn't have anything to Qt.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  8. #8
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: sorting QList<double>

    I was just saying qSort is not 'the only' way as you suggested.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Sorting using qSort(), - if QList contains POINTERS
    By joseph in forum Qt Programming
    Replies: 13
    Last Post: 18th August 2013, 19:55
  2. sorting QList<float>
    By timmu in forum Newbie
    Replies: 2
    Last Post: 23rd January 2012, 18:16
  3. Program not finding an existing double in a QList<double>
    By aarelovich in forum Qt Programming
    Replies: 2
    Last Post: 9th May 2011, 21:59
  4. sorting static QList<MyClass> list with qSort
    By oruccim in forum Qt Programming
    Replies: 3
    Last Post: 15th December 2010, 17:13
  5. Replies: 5
    Last Post: 18th December 2008, 14:58

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.