QMLProfiler 中的 QML Listview 报告两次委托创建

Posted

技术标签:

【中文标题】QMLProfiler 中的 QML Listview 报告两次委托创建【英文标题】:QML Listview in QMLProfiler reporting twice delegate creation 【发布时间】:2020-06-18 13:32:14 【问题描述】:

这是一个只有 10 个项目的简单 ListView。当我为此应用程序运行 QMLProfiler 时,统计数据显示创建委托的调用次数是两倍。有人可以解释一下这种行为吗?

import QtQuick 2.12
import QtQuick.Window 2.12

Window 
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    ListView
        anchors.fill: parent
        model: 10
        delegate: Rectangle
            width: parent.width
            height: 60
            Text 
                id: name
                text: qsTr("Item is ") + index
            
        
    

【问题讨论】:

【参考方案1】:

可以从 Qt 错误报告 QML Profiler shows double amount of Repeater delegate Create calls 中找到答案:

对象创建通常分两个阶段进行,这两个阶段被计算在内 分别在探查器中。

每个对象创建都涉及一个创建阶段和一个回调 组件完成()。这些是单独跟踪的。

【讨论】:

以上是关于QMLProfiler 中的 QML Listview 报告两次委托创建的主要内容,如果未能解决你的问题,请参考以下文章