如何从QML访问QModelIndex行

Arm*_*enB 4 c++ qt qml

我的QML代码中有这个:

TreeView {
    ...
    onExpanded: {
        console.log("onExpanded called", index)
    }
}
Run Code Online (Sandbox Code Playgroud)

这是它被称为时的输出:

QModelIndex(1,0,0x5d9f5a0,TreeModel(0x5deae90))
Run Code Online (Sandbox Code Playgroud)

如何访问1QML代码中的第一个值()?

der*_*erM 6

如果你在QML中有一个Object并且你不知道如何访问它的属性,你总是可以使用:Object.keys(obejectInQuestion).

至少对于QModelIndex你得到ListModel的吸气剂row()是用于财产row.所以要访问它,请使用:myQModelIndexThingy.row而不是myQModelIndexThingy.row()