Hello

I am trying to write the sort function for a QStringList object. I know that there is already a built-in function, but it is not sufficient for what I need because it only sorts ascending.

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

This is based on examples provided in the QtAlgorithms documentation. The problem I am having is that when I try to compile I get a compile-time error:

term does not evaluate to a function taking 2 arguments
c:\Qt\4.1.0\include\QtCore\../../src\corelib\tools\qalgorithms.h(141) : see reference to function template instantiation 'void QAlgorithmsPrivate::qSortHelper<BiIterator,T,LessT han>(BiIterator,BiIterator,const T &,LessThan)' being compiled
with
[
BiIterator=QList<QString>::iterator,
T=QString,
LessThan=bool (__thiscall MyClass::* )(const QString &,const QString &)
]
myclass.cpp(90) : see reference to function template instantiation 'void qSort<QList<T>::iterator,bool(__thiscall MyClass::* )(const QString &,const QString &)>(BiIterator,BiIterator,LessThan)' being compiled
with
[
T=QString,
BiIterator=QList<QString>::iterator,
LessThan=bool (__thiscall MyClass::* )(const QString &,const QString &)
]


I am new to Qt and my C++ is very rusty. I would appreciate some advice with regards to debugging this problem and/or interpreting this error msg.

Thanks in advance,

Jimmy