ListModel and item



  • My situation is a ListModel and some objects in it:

            ScrollView {
                id: scrollView1
                ListView {
                    id: listView;
                    model: listViewModel;
                    delegate: listViewDelegate;
                }
            }
    
            Component {
                id: listViewDelegate;
                QQShareObject {
                }
            }
    
            ListModel {
                id: listViewModel;
            }
    

    How can I call a function into QQShareObject objects?
    I tried
    listViewModel.get(0).internalFunction()
    but does not work..
    I need to have the current value of my QQShareObject object.


  • Moderators

    Hi,
    @mrdebug

    Try this

    listView.currentIndex = 6 // or whatever
    console.log(listView.currentItem) // gives the item at 6th position
    

    You can then access its properties. For eg:

    listView.currentItem.myId
    


  • This post is deleted!


  • for (var count= 0; count< listView.count; count++) {
    listView.currentIndex= count
    console.log(listView.currentItem.getValue())
    }

    is not a good solution. The line
    listView.currentIndex= count
    changes the current selected item.
    Is possible to have the value of each items without to change the item index?


  • Moderators

    @mrdebug then the other way to access delegate would be to use children
    For eg:

    view.contentItem.children[2].myId 
    

    view = id of ListView and myId is declared as Q_PROPERTY in QQShareObject



  • Perfect!


Log in to reply
 

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