High CPU usage when the view containing animation is not shown



  • 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



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

    While high CPU usage looks odd.



  • 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.



  • 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.



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.