문제

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

도움이 되었습니까?

해결책

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);
            }


}

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top