繁体   English   中英

Qt Quick非常慢画

[英]Qt Quick very slow painting

我刚刚开始研究Qt Quick,我有一个非常基本的程序,基本上与启动Qt Quick Controls应用程序项目时相同。

问题是,当我尝试调整窗口大小时,需要很长时间才能完成。 这可以在下面的.gif中看到。

问题

我可以在网上找到关于遇到类似问题的人的唯一信息是,您可以使用QML Profiler查找生成延迟的位置,有时这是由调试器引起的。 所以下面你可以看到QML探查器和gif是在发布模式下录制的。

在此输入图像描述

据我所知,动画是锁定GUI线程,这导致渲染或重新绘制缓慢,但我不知道是什么导致它。

我很感激任何帮助解决问题。

并没有太多的代码。

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中

#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

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

import QtQuick 2.7

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

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")
        }
    }
}

规格: Windows 10,Qt 5.9,MSVC 2017


Qt论坛Cross Post

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

此修复程序是否解决了此问题?

我认为你有这个问题,因为软件渲染是在幕后使用的。 所以需要很长时间。 因此,要启用硬件渲染,您需要安装ANGLE驱动程序。 您的分析图片表明交换操作一直在进行,因此这实际上是将所有像素从CPU复制到GPU,这就是您看到这种滞后的原因。 我不同意@dtech它不会帮助你。 我使用ANGLE驱动程序在Windows上渲染相当复杂的GL 3D场景,所以QT能够做到这一点,我相信

在窗口调整大小时,qml必须重新评估大小的绑定。 因此,需要重新计算改变大小或具有锚属性的所有内容。 据我所知,QT使用openGL作为默认渲染器。 在窗口调整大小时,缓冲区openGL渲染需要调整大小,并且需要重新绘制完整的场景图。 但在此之前,如果单个元素的大小发生变化,则需要先重新渲染单个元素。 Qml在纹理中存储可见元素,因此必须重新创建元素大小调整纹理...

可能会发生更多事情,具体取决于您使用的元素或构建场景图的方式或批次的组成方式。

如果要调试场景图,可以通过设置环境变量来实现。 例如,您可以通过设置以随机颜色进行更改

QSG_VISUALIZE=changes

有关Qt Quick Scene Graph Renderer的更多信息,请点击这里。

暂无
暂无

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

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