如何访问 Repeater 中 Loader 中的 QtObject?

How to access the QtObject inside the Loader inside a Repeater?

假设我有一个 QtObjectLoader 加载,它嵌入 Repeater(它本身附加到某个任意 ListModel)。

如何访问 QtObject 的属性和功能?

Repeater {
        id: repeater
        model: listModel
        Loader {
            sourceComponent: QtObject {
                   property int width: 100
                   property int height: 100

                   function foo() {console.log("bar")}
               }
            }
        }
    }

首先,您使用 itemAt() function and then the QtObject using item 属性:

访问加载程序
var loader = repeater.itemAt(index)
var qt_object = loader.item
console.log(qt_object)