简体   繁体   English

Qt Quick非常慢画

[英]Qt Quick very slow painting

I have just started to look at Qt Quick and I have a very basic program, essentially the same as when you start a Qt Quick Controls application project. 我刚刚开始研究Qt Quick,我有一个非常基本的程序,基本上与启动Qt Quick Controls应用程序项目时相同。

The problem is when I try to resize the window it takes a very long time to do so. 问题是,当我尝试调整窗口大小时,需要很长时间才能完成。 This can be seen in the .gif below. 这可以在下面的.gif中看到。

问题

The only information I could find on the web about people having a similar problem was that you could use the QML Profiler to find where the lag is being generated and sometimes it is due to the debugger. 我可以在网上找到关于遇到类似问题的人的唯一信息是,您可以使用QML Profiler查找生成延迟的位置,有时这是由调试器引起的。 So below you can see the QML profiler and the gif was recorded in release mode. 所以下面你可以看到QML探查器和gif是在发布模式下录制的。

在此输入图像描述

As far as I can tell the animation is locking the GUI thread up which is causing the render or repainting to be slow but I am not sure what is causing it. 据我所知,动画是锁定GUI线程,这导致渲染或重新绘制缓慢,但我不知道是什么导致它。

I would appreciate any help in solving the problem. 我很感激任何帮助解决问题。

And there is not much code to it. 并没有太多的代码。

Test.pro Test.pro

QT += qml quick
CONFIG += c++11
SOURCES += main.cpp
RESOURCES += qml.qrc
QML_IMPORT_PATH =
QML_DESIGNER_IMPORT_PATH =
DEFINES += QT_DEPRECATED_WARNINGS
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

main.cpp main.cpp中

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QLatin1String("qrc:/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}

main.qml main.qml

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    SwipeView {
        id: swipeView
        anchors.fill: parent
        currentIndex: tabBar.currentIndex

        Page1 {
            Label {
                text: qsTr("First page")
                anchors.centerIn: parent
            }
        }

        Page {
            Label {
                text: qsTr("Second page")
                anchors.centerIn: parent
            }
        }

        Page {
            Label {
                text: qsTr("Third page")
                anchors.centerIn: parent
            }
        }
    }

    footer: TabBar {
        id: tabBar
        currentIndex: swipeView.currentIndex
        TabButton {
            text: qsTr("First")
        }
        TabButton {
            text: qsTr("Second")
        }
        TabButton {
            text: qsTr("Third")
        }
    }
}

Page1.qml Page1.qml

import QtQuick 2.7

Page1Form {
    button1.onClicked: {
        console.log("Button Pressed. Entered text: " + textField1.text);
    }
}

Page1Form.ui.qml Page1Form.ui.qml

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3

Item {
    property alias textField1: textField1
    property alias button1: button1

    RowLayout {
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.topMargin: 20
        anchors.top: parent.top

        TextField {
            id: textField1
            placeholderText: qsTr("Text")
        }

        Button {
            id: button1
            text: qsTr("Press Me")
        }
    }
}

Specs: Windows 10, Qt 5.9, MSVC 2017 规格: Windows 10,Qt 5.9,MSVC 2017


Qt Forum Cross Post Qt论坛Cross Post

Recently this Qt Bug was fixed, since 5.9.2: https://bugreports.qt.io/browse/QTBUG-59893 最近这个Qt Bug被修复了,因为5.9.2: https//bugreports.qt.io/browse/QTBUG-59893

Does this fix solve this issue? 此修复程序是否解决了此问题?

I think you have this issue because software rendering is used under the hood. 我认为你有这个问题,因为软件渲染是在幕后使用的。 So it takes pretty long. 所以需要很长时间。 So to enable hardware rendering, you need to install ANGLE drivers. 因此,要启用硬件渲染,您需要安装ANGLE驱动程序。 Your profiling picture states that swap operation is taking all the time, so this is actually copying all the pixels from CPU to GPU, so that is why you see this lag. 您的分析图片表明交换操作一直在进行,因此这实际上是将所有像素从CPU复制到GPU,这就是您看到这种滞后的原因。 I don't agree with @dtech that it wont help you. 我不同意@dtech它不会帮助你。 I used ANGLE drivers for rendering pretty complex GL 3D scenes on Windows, so QT is capable of that, I am sure 我使用ANGLE驱动程序在Windows上渲染相当复杂的GL 3D场景,所以QT能够做到这一点,我相信

On a window resize qml has to reevaluate the bindings for size. 在窗口调整大小时,qml必须重新评估大小的绑定。 So everything that changed size or has anchor properties needs to be recalculated. 因此,需要重新计算改变大小或具有锚属性的所有内容。 As far as i know QT uses openGL as default renderer. 据我所知,QT使用openGL作为默认渲染器。 On a window resize the buffer openGL renders to needs to be resized aswell and the complete scenegraph needs to be repainted. 在窗口调整大小时,缓冲区openGL渲染需要调整大小,并且需要重新绘制完整的场景图。 But before that happens the single elements need to be rerendered first if their size changed. 但在此之前,如果单个元素的大小发生变化,则需要先重新渲染单个元素。 Qml stores visible elements in textures so as elements resize textures have to be recreated... Qml在纹理中存储可见元素,因此必须重新创建元素大小调整纹理...

Probably there is even more happening depending on what elements you use or how your scenegraph is build or how your batches are composed. 可能会发生更多事情,具体取决于您使用的元素或构建场景图的方式或批次的组成方式。

If you want to debug the scenegraph you can do so by setting enviroment vars. 如果要调试场景图,可以通过设置环境变量来实现。 For example you can make changes flash in random colors by setting 例如,您可以通过设置以随机颜色进行更改

QSG_VISUALIZE=changes

More info about Qt Quick Scene Graph Renderer here. 有关Qt Quick Scene Graph Renderer的更多信息,请点击这里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM