how to access qml ContextProperty variable in ListItemComponent of ListView

352 views Asked by At

I have problem to access exposed qml context Property variable in ListItemComponent.

e.g

applicationUI class:

qml->setcontextProperty("activeFrame",mActiveFrame);

main.qml

ListView{

id:model

      listItemComponents: [
                ListItemComponent {
                    id: listComponent
                    type:"item"

                    customListItem{

                             // here,i want to update cover.

                              // but error occur ,ReferenceError: Can't find variable: activeFrame

                              onPlayerStarted:{

                                   activeFrame.isPlaying(true)

                              }

                             onPlayerStopped:{

                                 activeFrame.isPlaying(false)
                              }

                           }

                 }

         ]

}

thanks

2

There are 2 answers

0
Ankur On BEST ANSWER

I found a solution.

To use activeFrame in ListitemComponent, we have to make new function in listview and call from customListItem.

 ListView{
        id:model
        listItemComponents: [
            ListItemComponent {
                id: listComponent
                type:"item"

                customListItem{
                    id:listItem

                    onPlayerStarted:{
                        listItem.ListItem.view.playingActiveFrame();
                    }

                    onPlayerStopped:{
                        listItem.ListItem.view.resetActiveFrame();
                    }
                }
            }
        ]
      function playingActiveFrame(){
                activeFrame.isPlaying(true);
            }
      function resetActiveFrame(){
               activeFrame.isPlaying(false);
            }


}
0
Bojan Kogoj On

Haven't tested, but something like this should work.

ListView{
    id:model
    listItemComponents: [
        ListItemComponent {
            id: listComponent
            type:"item"

            customListItem{
                id:listItem

                onPlayerStarted:{
                    listItem.ListItem.view.activeFrame.isPlaying(true)
                }

                onPlayerStopped:{
                    listItem.ListItem.view.activeFrame.isPlaying(false)
                }
            }
        }
    ]
}

Because:

For some odd reason the listItemComponents are outside of the normal code flow. But you can work around it. Give your listItemComponent a name/id. Then you can reference trough the the parent ListView. Source