PDA

View Full Version : sorting static QList<MyClass> list with qSort



oruccim
15th December 2010, 16:24
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...

FelixB
15th December 2010, 16:35
first: check if caseInsensitiveLessThan gets called (use a debugger or qDebug())
second: check if QList::begin() and QList::end() return what you expect

oruccim
15th December 2010, 16:54
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

nightghost
15th December 2010, 17:13
is your list already sorted? (maybe in the opposite direction?) or is your list const?