Jimmy2775
10th February 2006, 21:14
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:
QStringList MyClass::sort(QStringList stringList, Qt::SortOrder order)
{
if ( order == Qt::AscendingOrder )
{
qSort(stringList.begin(), stringList.end(), caseInsensitiveLessThan);
}
else
{
qSort(stringList.begin(), stringList.end(), caseInsensitiveGreaterThan);
}
return stringList;
}
bool MyClass::caseInsensitiveLessThan(const QString &s1, const QString &s2)
{
return s1.toLower() < s2.toLower();
}
bool MyClass::caseInsensitiveGreaterThan(const QString &s1, const QString &s2)
{
return s1.toLower() > s2.toLower();
}
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,LessThan>(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
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:
QStringList MyClass::sort(QStringList stringList, Qt::SortOrder order)
{
if ( order == Qt::AscendingOrder )
{
qSort(stringList.begin(), stringList.end(), caseInsensitiveLessThan);
}
else
{
qSort(stringList.begin(), stringList.end(), caseInsensitiveGreaterThan);
}
return stringList;
}
bool MyClass::caseInsensitiveLessThan(const QString &s1, const QString &s2)
{
return s1.toLower() < s2.toLower();
}
bool MyClass::caseInsensitiveGreaterThan(const QString &s1, const QString &s2)
{
return s1.toLower() > s2.toLower();
}
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,LessThan>(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