我认为,问题是两个时间戳是不相等的。如果你检查QDateTime
的==
运营商代码,你会看到等式成立,如果时间和日期是相等的。
bool QDateTime::operator==(const QDateTime &other) const
{
if (d->spec == other.d->spec && d->utcOffset == other.d->utcOffset)
return d->time == other.d->time && d->date == other.d->date;
else {
QDate date1, date2;
QTime time1, time2;
d->getUTC(date1, time1);
other.d->getUTC(date2, time2);
return time1 == time2 && date1 == date2;
}
}
但是等于操作的时间或比较毫秒:
bool operator==(const QTime &other) const { return mds == other.mds; }
其中mds
是在毫秒的时间。在QTime
构造mds
的计算方法如下:
mds = (h*SECS_PER_HOUR + m*SECS_PER_MIN + s)*1000 + ms;
这将是安全,如果你只是检查是否两个时间戳之间的差别在一个限度内。例如:
while (it != _reminders.end() && abs(now.msecsTo(it.key())) < aLimitInMsecs) {
是“它”指向“_reminders.end()”后查找或有效的项目? – Koying 2012-03-06 12:17:39
在进入循环之前,我检查了'it == _reminders.end()'的条件。这是真的,这就是为什么循环从未被执行。但为什么? “QDateTime”的比较运算符可以与此有关吗? – Pieter 2012-03-06 12:42:45