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?


  • Moderators

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



  • class MyClass: public QObject {
      Q_OBJECT
      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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.