5

How do I sort a QList of QDateTime* objects by the value of the QDateTime object?

Jon
  • 3,985
  • 7
  • 48
  • 80

1 Answers1

12

You can use qSort with your own comparison function:

#include <QtAlgorithms>

bool dtcomp(QDateTime* left, QDateTime *right) {
  return *left < *right;
}

QList<DateTime*> dtlist = ...;
qSort(dtlist.begin(), dtlist.end(), dtcomp);
sth
  • 222,467
  • 53
  • 283
  • 367