Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Why is QDateTime operator < seems to not work? [solved]
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?
Unless I'm having brain fart it looks like < and > returned values are backwards.
double post srry.
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
Line that doesn't work, at the same time the above was taken from debugger.
if ( pIndex->mDateTimeUTC < nowUTC )
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.
You could open a bug report for the documentation to have it updated