Important: Please read the Qt Code of Conduct -

ListView CurrentItem get underlying object

  • Hi,
    I display C++ object in ListView (model is QQmlListProperty). I can access individual objects in listview's delegate via model.modelData.

    How can I access C++ objects via currentItem property ofthe ListView?

  • Hi! Can you please show some code to clearify the matter?

  • class MyClass: public QObject {
      Q_PROPERTY(QQmlListProperty<MyType> myList READ myList NOTIFY myListChanged)
      QQmlListProperty<MyType> myList(void) {
        return QQmlListProperty<MyType>(this, myQList);
      QList<MyType *> myQList;

    And QML:

                GridView {
                    model: myList // see property myList in MyClass
                    onCurrentItemChanged: {
                         // here I want to access property of currently selected MyType object

Log in to reply