Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access QModelIndex row from QML

Tags:

c++

qt

qml

I have this in my QML code:

TreeView {
    ...
    onExpanded: {
        console.log("onExpanded called", index)
    }
}

And this is the output when it's called:

QModelIndex(1,0,0x5d9f5a0,TreeModel(0x5deae90))

how do I access the first value (1) inside QML code?

like image 334
ArmenB Avatar asked Jan 25 '17 18:01

ArmenB


1 Answers

If you've got an Object in QML and you don't know how to access it's properties, you can always use: Object.keys(obejectInQuestion).

At least for the QModelIndex you get for the ListModel the getter row() is used for the property row. So to access it, use: myQModelIndexThingy.row instead of myQModelIndexThingy.row()

like image 79
derM Avatar answered Nov 04 '22 02:11

derM