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

QVariantAnimation goes too fast when QQmlApplicationEngine shows window

    XMLWordPrintable

Details

    Description

      The update interval of the QVariantAnimation goes too quickly when QVariantAnimation is used at the same time as a QQmlApplicationEngine.

      Reproduction code attached.

      Out of the box, the 10,000ms animation output ends something like this:

      ...
      Current Time 9960 CurrentInterval 16 IntervalCount 623 IntervalTime 16
      Current Time 9976 CurrentInterval 16 IntervalCount 624 IntervalTime 16
      Current Time 9992 CurrentInterval 16 IntervalCount 625 IntervalTime 16
      Current Time 10000 CurrentInterval 8 IntervalCount 626 IntervalTime 16
      Elapsed 10013
      

      However when the engine is allowed to load the QML (by uncommenting the engine.load() line), the animation goes too fast:

      ...
      Current Time 9966 CurrentInterval 16 IntervalCount 598 IntervalTime *5*
      Current Time 9983 CurrentInterval 17 IntervalCount 599 IntervalTime *5*
      Current Time 10000 CurrentInterval 17 IntervalCount 600 IntervalTime *5*
      Elapsed *3547*
      

      You can see that the animation which should have taken 10,000 ms only took 3547. The currentInterval is the difference in values in the call to updateCurrentTime. This seems to be correct. What is not correct is the time between those calls - only 5ms! This means that the animation completes in around 30% of the time.

      Note that if the root object of the QML is changed to something other than Window/ApplicationWindow e.g. Item, the animation rate returns to the correct ~16ms.

      In addition, if I take out the QQmlApplicationEngine and replace it with a QWindow w and show it, the problem doesn't occur but when creating a QQuickWindow instead and showing it, the problem does occur.

      Interestingly, publishing the type to QML and using it only there has the same issue:

      qmlRegisterType<VariantAnimation>("VariantAnimation", 1, 0, "VariantAnimation");
      
      import QtQuick 2.3
      import QtQuick.Controls 1.2
      import QtQuick.Window 2.2
      import VariantAnimation 1.0
      
      ApplicationWindow {
          id: window
      
          width: 300
          height: 100
      
          visible: true
      
          VariantAnimation {
              startValue: 0
              endValue: 1000
              duration: 10000
      
              property var now
      
              onStateChanged: if(state == VariantAnimation.Running) now = new Date()
              onFinished: console.log(new Date() - now)
      
              Component.onCompleted: start()
          }
      }
      

      Attachments

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

        Activity

          People

            sletta Gunnar Sletta
            miketrahearn Mike Trahearn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes