我正在尝试根据 QDateTime 对 QList 进行排序,但出现以下错误:
must use '.*' or '->*' to call pointer-to-member function in 'lessThan (...)', e.g. '(... ->* lessThan) (...)'
if (lessThan(*end, *start))
^
Run Code Online (Sandbox Code Playgroud)
排序功能:
bool sortRecord(Record left, Record right){
return left.getArrival().getDate() < right.getArrival().getDate();
}
Run Code Online (Sandbox Code Playgroud)
函数是这样调用的:
qSort(recordList.begin(), recordList.end(), sortRecord);
Run Code Online (Sandbox Code Playgroud)
Record 中到达的 getter 和 setter:
void Record::setArrival(Arrival arrival){
this->arrival = arrival;
}
Arrival Record::getArrival(){
return this->arrival;
}
Run Code Online (Sandbox Code Playgroud)
getDate() 到达功能:
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); …Run Code Online (Sandbox Code Playgroud) 当我尝试仅从时间戳获取时间时,我遇到了问题。
时间戳的一个示例是:
2012-04-19T23:05:00 + 0200
我认为格式是“ yyyy-MM-dd'T'HH:mm:ss.SSSZ”,对吗?并且必须为“ HH:mm”。
我使用以下代码,但不返回任何内容:
public String getTime(String Vertrektijd){
final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date dateObj;
String newDateStr = null;
try
{
dateObj = df.parse(Vertrektijd);
SimpleDateFormat fd = new SimpleDateFormat("HH:mm");
newDateStr = fd.format(dateObj);
}
catch (Exception e)
{
e.printStackTrace();
}
return newDateStr;
}
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助!