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

Real animation duration not equals to declared time

    XMLWordPrintable

Details

    Description

      Any animation completes quicker than declared in two times.

      E.g. when animation duration is 5000 msecs, then it completes in ~2700 msecs. Please see following code (also see an example project from attach).

      = main.qml =

      iimport QtQuick 2.4
      
      Rectangle {
          id: root
          color: "red"
          anchors.fill: parent
          Rectangle {
              color: "green"; width: 50; height: 50;
              NumberAnimation on x {
                  running: true; from: 0; to: 1000; duration: 5000;
                  onStopped: {
                      calculator.qmlAnimationElapsed();
                      start();
                  }
              }
          }
      
          Timer {
              interval: 1000; running: true; repeat: true
              onTriggered: calculator.qmlTimerElapsed();
          }
      }
      

      = main.cpp =

      #include <QGuiApplication>
      #include <QQuickView>
      #include <QQmlContext>
      #include <QElapsedTimer>
      #include <QTimer>
      #include <QDebug>
      
      class Calculator : public QObject
      {
          Q_OBJECT
      public:
          explicit Calculator(QObject *parent = nullptr)
              : QObject(parent)
          {
              m_animation.start();
              m_timer.start();
          }
      
          Q_INVOKABLE void qmlAnimationElapsed()
          {
              qDebug() << "QML animation elapsed:" << m_animation.elapsed();
              m_animation.start();
          }
      
          Q_INVOKABLE void qmlTimerElapsed()
          {
              qDebug() << "QML timer elapsed:" << m_timer.elapsed();
              m_timer.start();
          }
      
      private:
          QElapsedTimer m_animation;
          QElapsedTimer m_timer;
      };
      
      int main(int argc, char *argv[])
      {
          QGuiApplication app(argc, argv);
      
          QElapsedTimer elapsedTimer;
          QTimer timer;
      
          QGuiApplication::connect(&timer, &QTimer::timeout, [&elapsedTimer]() {
              qDebug() << "C++ timer elapsed:" << elapsedTimer.elapsed();
              elapsedTimer.start();
          });
      
          elapsedTimer.start();
          timer.start(1000);
      
          Calculator calculator;
      
          QQuickView view;
          view.rootContext()->setContextProperty("calculator", &calculator);
          view.setSource(QUrl(QStringLiteral("qrc:/main.qml")));
          view.setResizeMode(QQuickView::SizeRootObjectToView);
          view.showFullScreen();
      
          return app.exec();
      }
      
      #include "main.moc"
      

      Debug output:

      C++ timer elapsed: 1125
      QML timer elapsed: 1597
      QML timer elapsed: 447
      C++ timer elapsed: 974
      QML timer elapsed: 462
      QML timer elapsed: 454
      C++ timer elapsed: 1025
      QML animation elapsed: 3412
      QML timer elapsed: 450
      QML timer elapsed: 452
      C++ timer elapsed: 1000
      QML timer elapsed: 451
      QML timer elapsed: 452
      C++ timer elapsed: 1001
      QML timer elapsed: 456
      QML animation elapsed: 2278
      QML timer elapsed: 464
      C++ timer elapsed: 998
      QML timer elapsed: 454
      QML timer elapsed: 454
      QML timer elapsed: 451
      C++ timer elapsed: 999
      QML timer elapsed: 452
      QML animation elapsed: 2270
      QML timer elapsed: 457
      C++ timer elapsed: 999
      QML timer elapsed: 454
      QML timer elapsed: 454

      The QTimer works as expected, but the QML's timer lies!!!

      Attachments

        1. image-2023-04-12-02-46-20-305.png
          333 kB
          Carlos Pérez
        2. qml-timers-test.tar.bz2
          4 kB
          Denis Shienkov
        3. qt-for-apalis-imx6-configure-qt5.8
          2 kB
          Denis Shienkov

        Issue Links

          Activity

            People

              sletta Gunnar Sletta
              kuzulis Denis Shienkov
              Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated: