c++linuxwindowsqtqtime

QTime behaving different in linux and windows platforms


I have same Qt code which runs in both linux and windows . But it is acting different in each case. In linux it is behaving correct , but while in windows it is not.

In linux it is behaving as follows

In Windows it is behaving as follows

you can see that in windows platform it is returning null string and in linux platform it is behaving as expected. What could be the reason ?


Solution

  • The default constructor of QTime produces an invalid time, most operations on an invalid time will fail or return another invalid time. Calling addSecs still leaves you with an invalid time and calling toString on an invalid time returns an empty string.

    To construct a QTime of midnight you need to use:

    QTime time(0,0);