Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    6
    2642
    Loading More Posts
    • 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
      pwnstar23 last edited by

      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 Reply Quote 0
      • P
        pwnstar23 last edited by

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

        1 Reply Last reply Reply Quote 0
        • P
          pwnstar23 last edited by

          double post srry.

          1 Reply Last reply Reply Quote 0
          • P
            pwnstar23 last edited by

            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 Reply Quote 0
            • P
              pwnstar23 last edited by

              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 Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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 Reply Quote 0
                • First post
                  Last post