Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. High CPU usage when the view containing animation is not shown
Forum Updated to NodeBB v4.3 + New Features

High CPU usage when the view containing animation is not shown

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 4.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xylosper
    wrote on last edited by
    #1

    Here's a very simple QML code including an animation:
    @import QtQuick 2.0

    Rectangle {
    ColorAnimation on color { loops: Animation.Infinite; from: "white"; to: "black"; duration: 5000 }
    }
    @

    I executed this qml code with next C++ code:
    @#include <QGuiApplication>
    #include <QQuickView>

    int main(int argc, char **argv) {
    QGuiApplication app(argc, argv);
    QQuickView view;
    view.setSource(QUrl::fromLocalFile("/path/to/qml"));
    view.setResizeMode(QQuickView::SizeRootObjectToView);
    view.resize(100, 100);
    view.show();
    return app.exec();
    }@

    As far as I'm seeing the scene, there's no problem and the CPU usage hits only about 5%.
    However, the window is hidden by being minimized or covered other windows, the CPU usage reaches to about 90%.
    If I recover the window shown normal, CPU usage also decreses to normal percentage(<5%).
    Without animantions, the problem does not occur.
    Should I file a bugreport? Or is there any solution to prevent extremely high CPU usage when the window is hidden?

    For your information, here's my testing environment:
    OS: Mac OS X 10.7.5, CPU: 2.7GHz Intel Core i7, Memory: 8GB DDR3, GPU: Intel HD 3000 512MB

    1 Reply Last reply
    0
    • D Offline
      D Offline
      daliusd
      wrote on last edited by
      #2

      You can stop() and start() it. http://doc.qt.digia.com/qt/qml-coloranimation-members.html

      While high CPU usage looks odd.

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xylosper
        wrote on last edited by
        #3

        Thanks for your reply.
        I can stop/start the animation when the window is minimized/restored.
        However, the problem ALSO occurs when the window is covered by any other window even if the window is not minimized.
        Can I know when the window is covered other window, and the covering window is gone?
        I can't find the event to achieve this in Qt doc.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          daliusd
          wrote on last edited by
          #4

          I'm not sure how to achieve this because I'm not developing for desktops anymore. Here my quick idea:

          QQuickView has "visible" and similar members (http://doc-snapshot.qt-project.org/5.0/qtquick/qquickview-members.html). You should figure out how to pass this information to QML and I think you will be good. Most probably you should pass your instance of QQuickView and that's all.

          1 Reply Last reply
          0
          • X Offline
            X Offline
            xylosper
            wrote on last edited by
            #5

            Thanks, again. My application is already pass/call data and functions between C++ and QML. What I really want to know is how I can notice the window is obscured by other window, so that I hide or stop animation.

            Anyway, I reported this problem, and it is confirmed as a bug.
            https://bugreports.qt-project.org/browse/QTBUG-29137

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved