1

I have a listview in my homepage which has a custom listitem component. I have a value in my Qsettings variable which I can access in homepage but I'm unable to access the same inside the custom listitem component. When loading the homepage the Qsetting data log gets printed onCreationCompleted of homepage but shows error in onCreationCompleted of customlistitemhomepage. Below is a piece of sample code for my homepage structure and the customlistitemhomepage structure.

Page {
    Container {
        layout: DockLayout {
        }
        ScrollView {
            id: homePageScroll
            Container {
                layout: DockLayout {
                }
                ListView {
                    id: contactListView
                    dataModel: contactsData
                    preferredHeight: homePageScroll.listHeight
                    overlapTouchPolicy: OverlapTouchPolicy.Allow
                    listItemComponents: [
                        ListItemComponent {
                            id: homeListComponent
                            type: "item"
                            CustomListItemHomePage {
                                id: listCell
                            }
                            //Some code
                        }
                    ]
                }
            }
        }

        onCreationCompleted: {
                 console.log("Clipboard value:"+_settings.getValueFor("clipBoard", "No Data")); //THIS PRINTS CORRECTLY
        }
    }
}

I have also logged the same inside the CustomListItemHomePage.qml

 CustomListItemHomePage {
     onCreationCompleted: {
         console.log("Clipboard value:"+_settings.getValueFor("clipBoard", "No Data")); //THIS SHOWS ERROR CAN'T Find variable _settings
     }                             
 }
nonesuchnick
  • 627
  • 4
  • 17
Francis F
  • 3,157
  • 3
  • 41
  • 79

1 Answers1

0

The listItemComponents can't have right to call function outside from Listview. So if you want to call QSettings function in CustomListItemHomePage.qml, you can do like:

ListView {
    id: contactListView
    dataModel: contactsData
    preferredHeight: homePageScroll.listHeight
    overlapTouchPolicy: OverlapTouchPolicy.Allow
    listItemComponents: [
        ListItemComponent {
            id: homeListComponent
            type: "item"
            CustomListItemHomePage {
                id: listCell
                // Now you are able to call getClipboardValue() from ListItemComponent like 
                // listCell.ListItem.view.getClipboardValue() 
            }
            //Some code
        }
    ]
    function getClipboardValue() {
        return _settings.getValueFor("clipBoard", "No Data"));
    }
}
nonesuchnick
  • 627
  • 4
  • 17
Ankur
  • 1,385
  • 11
  • 21
  • How do I access this returned value in CustomListItemHomePage? Is there any way to trigger a function inside CustomListItemHomePage.qml from the listview in homepage.qml? – Francis F Jan 09 '15 at 12:53
  • No, Its depends upon you how do you gonna use it. – Ankur Jan 09 '15 at 17:05