Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt 5.0: QQuickView blocks GUI thread
Forum Updated to NodeBB v4.3 + New Features

Qt 5.0: QQuickView blocks GUI thread

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 2.5k 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.
  • P Offline
    P Offline
    Peter K
    wrote on last edited by
    #1

    When forcing the QQuickView to update at 60Hz or faster, the main GUI thread blocks. Resizing and moving the window no longer works.
    Connecting the beforeRendering() signal to a function that prints the current thread (using DirectConnection) shows that the rendering is not taking place in a separate rendering thread, unlike the documentation suggests.

    Problem: Why is the QQuickView not doing the rendering in a separate thread, as the docs suggest it would?

    The code below shows the problem. The timer forces the QQuickView to update at 100Hz (which is limited to 60Hz, as can be seen in the qDebug() messages).
    The code also shows that, were you to disable the timer and trigger the infinite animation by clicking the contents, it will also start updating at 60Hz, and block the main GUI thread.

    Both forced updates and Qml animations block the main GUI thread.

    main.cpp:
    @
    #include <QtGui>
    #include <QtOpenGL>
    #include <QtQuick>

    #include "myobject.h"

    int main(int argc, char** argv)
    {
    QGuiApplication app(argc, argv);

    qDebug() << QThread::currentThread();
    
    QQuickView view(QUrl("main.qml"));
    QObject::connect(view.engine(), SIGNAL(quit()), &view, SLOT(close()));
    view.show();
    
    MyObject obj;
    QObject::connect(&view, SIGNAL(beforeRendering()), &obj, SLOT(notify()), Qt::DirectConnection);
    
    QTimer timer;
    QObject::connect(&timer, SIGNAL(timeout()), &view, SLOT(update()));
    timer.start(10);
    
    app.exec&#40;&#41;;
    

    }
    @

    myobject.h:
    @
    #pragma once
    #include <QtGui>

    class MyObject : public QObject
    {
    Q_OBJECT

    public slots:
    void notify()
    {
    qDebug() << QThread::currentThread() << time.nsecsElapsed();
    time.restart();
    }

    private:
    QElapsedTimer time;
    };
    @

    main.qml:
    @
    import QtQuick 2.0

    Rectangle {
    width: 360
    height: 360
    Text {
    id: text
    text: qsTr("Hello World")
    x: 50
    y: 180

        NumberAnimation {
            id: ani
            loops: Animation.Infinite
            target: text
            property: "x"
            duration: 200
            easing.type: Easing.InOutQuad
            from: 50
            to: 250
        }
    }
    MouseArea {
        anchors.fill: parent
        onClicked: {
            ani.start()
        }
    }
    

    }
    @

    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