I am trying to sort my QList based on a QDateTime but I get the following error:
must use '.*' or '->*' to call pointer-to-member function in 'lessThan (...)', e.g. '(... ->* lessThan) (...)'
if (lessThan(*end, *start))
^
Sort function:
bool sortRecord(Record left, Record right){
return left.getArrival().getDate() < right.getArrival().getDate();
}
Function is called like this:
qSort(recordList.begin(), recordList.end(), sortRecord);
Getter and setter of arrival in Record:
void Record::setArrival(Arrival arrival){
this->arrival = arrival;
}
Arrival Record::getArrival(){
return this->arrival;
}
getDate()
function in Arrival:
QDateTime Arrival::getDate(){
QDateTime qDateTime;
QDate qDate;
qDate.setDate(date.getDateYear(), date.getDateMonth(), date.getDateDay());
qDateTime.setDate(qDate);
vector<string> timeS = splitTime(time.getTimeFrom());
QTime qTime;
qTime.setHMS(stoi(timeS[0]), stoi(timeS[1]), 0);
qDateTime.setTime(qTime);
return qDateTime;
}
What is it that I do wrong?
Thanks!
lessThan
used, where is it declared? – CottonweedsortRecord
is a non-static member function, which you're passing to Qt's sorting function. Make it static, or liberate it entirely from the shackles of the class system. – Lavellelavenmain.cpp
- that's what should have been in your question to begin with. Your job is to throw out everything that doesn't contribute to the problem: it's just noise. – Back