Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why is QDateTime operator < seems to not work? [solved]

Why is QDateTime operator < seems to not work? [solved]

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pwnstar23
    wrote on last edited by
    #1

    In my code I have 2 UTC times. In the debuger they have the correct times. However even when the first one is clearly before ( < ) the second one, the < returns false?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pwnstar23
      wrote on last edited by
      #2

      Unless I'm having brain fart it looks like < and > returned values are backwards.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pwnstar23
        wrote on last edited by
        #3

        double post srry.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          pwnstar23
          wrote on last edited by
          #4

          Debugger contents.

          Locals
          nowUTC Thu Apr 11 22:18:31 2013 QDateTime

          pIndex @0xb971700 Meeting

          mBody "This is the body of a placeholder meeting." std::string

          mDateTimeUTC Thu Apr 11 22:08:10 2013 QDateTime

          mHeader "This is a fake meeting." std::string

          resave false bool

          this @0x28fe20 MeetingManager

          Inspector
          Expressions
          Return Value
          Tooltip

          Line that doesn't work, at the same time the above was taken from debugger.

          if ( pIndex->mDateTimeUTC < nowUTC )

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pwnstar23
            wrote on last edited by
            #5

            I solved this problem, but I had to look at the source code of Qt to see that the function is doing more than just comparing the times it also does work to compare time specs. The docs only say...

            bool QDateTime::operator<(const QDateTime & other) const
            Returns true if this datetime is earlier than the other datetime; otherwise returns false.

            So when I pulled my QDateTime from file the timespec was lost and I guess it assumed local, so setting the time spec to UTC after pulling from the file makes it work now.

            Someone should probably add a line to the docs that says the extra work is done.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              You could open a bug report for the documentation to have it updated

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved