Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7620255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:53:43+00:00 2026-05-31T03:53:43+00:00

I have a QMultiMap<QDateTime, SomeOwnDataType> from which I’d like to retrieve all values with

  • 0

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:

Debug

Contrary to my expectations, the loop was skipped entirely. How come?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:53:45+00:00Added an answer on May 31, 2026 at 3:53 am

    I believe that the problem is that the two timestamps are not equal. If you check the == operator code of QDateTime you will see that the equality holds if both time and date are equal.

    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;
        }
    }
    

    But the time equal operator compares miliseconds:

    bool operator==(const QTime &other) const { return mds == other.mds; }
    

    where mds is the time in miliseconds. In the QTime constructor mds is calculated as follows:

     mds = (h*SECS_PER_HOUR + m*SECS_PER_MIN + s)*1000 + ms;
    

    It would be safer if you just checked if the difference between two timestamps is within a limit. For example :

    while (it != _reminders.end() && abs(now.msecsTo(it.key())) < aLimitInMsecs) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a std::multimap where key is a custom class. Something like this: Class
Suppose that I have a multimap (which maps multiple values to a single key),
I have a multimap from which I want to free the memory allocated to
I have a guava HashMultimap like this Multimap<String, String> multiMap = HashMultimap.create(); multiMap.put(a, x);
Currently I have implemented a reference-counting cache of the values of the map like
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you managed to get Aptana Studio debugging to work? I tried following this,
Is there a simple or standard way to have a multimap iterator which iterate
I have a printout of all the addresses for you first. The thing im
I have data from a ResultSet that contains three fields: DataType, Data, DataValue. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.