Jon
Jon

Reputation: 4045

How do I sort a QList of QDateTime*?

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

Upvotes: 5

Views: 8067

Answers (1)

sth
sth

Reputation: 229573

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);

Upvotes: 12

Related Questions