Results 1 to 5 of 5

Thread: Sorting a StringList

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    13
    Thanked 6 Times in 5 Posts

    Default Re: Sorting a StringList

    That is simpler and does solve the error - thank you wysota.

    However, I would still like to know what the problem was with my origional code that would cause it not to compile so I can understand it better.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Sorting a StringList

    Quote Originally Posted by Jimmy2775
    However, I would still like to know what the problem was with my origional code that would cause it not to compile so I can understand it better.
    You were trying to use a pointer to a method instead of a pointer to a standalone function.

    This should work:
    Qt Code:
    1. bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
    2. {
    3. return s1.toLower() < s2.toLower();
    4. }
    5.  
    6. bool caseInsensitiveGreaterThan(const QString &s1, const QString &s2)
    7. {
    8. return s1.toLower() > s2.toLower();
    9. }
    10.  
    11. QStringList MyClass::sort(QStringList stringList, Qt::SortOrder order)
    12. {
    13. if ( order == Qt::AscendingOrder )
    14. {
    15. qSort(stringList.begin(), stringList.end(), caseInsensitiveLessThan);
    16. }
    17. else
    18. {
    19. qSort(stringList.begin(), stringList.end(), caseInsensitiveGreaterThan);
    20. }
    21. return stringList;
    22. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Edmonton, Canada
    Posts
    101
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    13
    Thanked 6 Times in 5 Posts

    Default Re: Sorting a StringList

    OK - I understand. Thank you.

Similar Threads

  1. Refresh QTableView after sorting
    By araglin in forum Newbie
    Replies: 4
    Last Post: 18th December 2008, 23:13
  2. Qt4: Sorting QAbstractItemVew inherited view
    By nando in forum Qt Programming
    Replies: 3
    Last Post: 12th February 2008, 19:30
  3. Column Sorting
    By sumsin in forum Qt Programming
    Replies: 1
    Last Post: 16th June 2006, 08:48
  4. QT4: Sorting in QTreeWidget (subclass)
    By Michiel in forum Qt Programming
    Replies: 21
    Last Post: 29th March 2006, 19:08
  5. [QT4] QTreeView, QAbstractItemModel and sorting
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 24th March 2006, 21:16

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.