Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-25128

Value returned by QElapsedTimer::msecsTo is negative of what it should be according to documentation

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • 4.8.2, 5.0.0
    • 4.7.4
    • Core: Date/Time
    • None
    • Tested on Windows, maybe other platforms have the correct behaviour
    • 6da3e4d865e391a1d291c4729f4771a87c6bcd65

    Description

      According to the documentation QElapsedTimer::msecsTo(QElapsedTimer other) returns a positive value if other was started before this. However, the actual implementation is exactly the other way round, it returns a positive value when this was started before other.

      Simple program to validate:

      #include <QElapsedTimer>
      #include <QThread>
      #include <QDebug>
      
      class Thread: public QThread
      {
      public:
          using QThread::sleep;
      };
      
      int main(int argc, char *argv[])
      {
          QElapsedTimer timer1;
          timer1.start();
      
          Thread::sleep(1);
      
          QElapsedTimer timer2;
          timer2.start();
      
          qDebug() << timer2.msecsTo(timer1);
          qDebug() << timer1.msecsTo(timer2);
      
          return 0;
      }
      

      Results in:

      -998
      998
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            jabernet Janick Bernet
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes