Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I sort a QList of QDateTime*?

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

like image 681
Jon Avatar asked Apr 18 '11 00:04

Jon


1 Answers

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);
like image 113
sth Avatar answered Oct 22 '22 07:10

sth