I have a QMultiMap<QDateTime, SomeOwnDataType> from which I’d like to retrieve all values with a certain timestamp. This is what I do:
QMap<QDateTime, Appointment>::iterator it = _reminders.find(now);
where now has a value of di 6. mrt 12:07:00 2012. This is my loop condition:
while (it != _reminders.end() && it.key() == now) {
This was the state of the _reminders object:

Contrary to my expectations, the loop was skipped entirely. How come?
I believe that the problem is that the two timestamps are not equal. If you check the
==operator code ofQDateTimeyou will see that the equality holds if both time and date are equal.But the time equal operator compares miliseconds:
where
mdsis the time in miliseconds. In theQTimeconstructormdsis calculated as follows:It would be safer if you just checked if the difference between two timestamps is within a limit. For example :