Results 1 to 4 of 4

Thread: sorting static QList<MyClass> list with qSort

  1. #1
    Join Date
    Dec 2010
    Posts
    2
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Symbian S60 Maemo/MeeGo

    Default sorting static QList<MyClass> list with qSort

    Hi All,
    i am trying to sort my a QList (static QList<MyClass> list; ) but nothing change on the
    list .
    here is the code
    bool caseInsensitiveLessThan(const Myclass s1, const Myclass s2)
    {
    return (s1.id < s2.id);
    }

    qSort(list.begin(),list.end(),caseInsensitiveLessT han);
    there is no error on my code. After adding this statements, my list is still same, nothing is changed.
    is there anyone have an idea why the list is still same,
    thank you...

  2. #2
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: sorting static QList<MyClass> list with qSort

    first: check if caseInsensitiveLessThan gets called (use a debugger or qDebug())
    second: check if QList::begin() and QList::end() return what you expect

  3. #3
    Join Date
    Dec 2010
    Posts
    2
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi
    Platforms
    Symbian S60 Maemo/MeeGo

    Default Re: sorting static QList<MyClass> list with qSort

    Quote Originally Posted by FelixB View Post
    first: check if caseInsensitiveLessThan gets called (use a debugger or qDebug())
    second: check if QList::begin() and QList::end() return what you expect
    first: caseInsensitiveLessThan is called i checked
    second: .begin() and .end() returns const iterator i get this example from the following link
    http://doc.trolltech.com/latest/qtalgorithms.html

  4. #4
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: sorting static QList<MyClass> list with qSort

    is your list already sorted? (maybe in the opposite direction?) or is your list const?
    Last edited by nightghost; 15th December 2010 at 16:18.

Similar Threads

  1. Sorting using qSort(), - if QList contains POINTERS
    By joseph in forum Qt Programming
    Replies: 13
    Last Post: 18th August 2013, 18:55
  2. How to qSort a Qlist of QPair?
    By Trader in forum Qt Programming
    Replies: 2
    Last Post: 7th July 2010, 19:04
  3. QList<MyClass> to const QList<const MyClass>
    By juanluispaz in forum Newbie
    Replies: 4
    Last Post: 6th May 2010, 19:27
  4. why doesn't qSort work when a QList hosts a pointertype?
    By momesana in forum Qt Programming
    Replies: 1
    Last Post: 4th October 2009, 04:28
  5. Replies: 5
    Last Post: 18th December 2008, 13: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.