Using qGreater<T> with custom objects ...
General and Desktop
4
Posts
3
Posters
1.1k
Views
1
Watching
-
Hi,
You need to implement the corresponding operator > for your custom object. If you are using Qt 5, you are encourage to use std::greater directly
-
That member is obsolete in Qt 5.4:
http://doc.qt.io/qt-5/qtalgorithms-obsolete.html
Anyway, you should implement your own function to compare your objects. Here you have an example:
@bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
{
return s1.toLower() < s2.toLower();
}int doSomething()
{
QStringList list;
list << "AlPha" << "beTA" << "gamma" << "DELTA";
qSort(list.begin(), list.end(), caseInsensitiveLessThan);
// list: [ "AlPha", "beTA", "DELTA", "gamma" ]
}@