Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
boytsov_s
Posts: 18
Registered: ‎01-31-2013
My Device: Dev Alpha
My Carrier: MobileTeleSystem
Accepted Solution

What is correnct way to use custom GroupDataModel inside a qml?

Hello.

Got this qml code 

    Tab {
        title: qsTr("Friends")
        content: NavigationPane {
            Page {
                content: ListView {
                	id: friendsView
                        dataModel: friendsModel 
                	listItemComponents: [
                        ListItemComponent {
                            type: "header"
                            StandardListItem {
                                title: friendsModel.header
                            }
                        },
                        ListItemComponent {
                            type: "item"
                            StandardListItem {
                                title: friendsModel.first_name
                                description: friendsModel.last_name
                            }
                        }
                	]
                }
                onCreationCompleted: {
                  if (friendsModel){
                    console.log("Here is non 0 model")
                    
                  }
                }    
            }

        } 
    }

 And this C++ code

    FriendsApiService* friendsApi = new FriendsApiService();
    friendsApi->getFriendsList();


    QmlDocument *qml = QmlDocument::create("asset:///main.qml")
    .parent(this);

    qml->setContextProperty("friendsModel", friendsApi);
    
    AbstractPane *root = qml->createRootObject<AbstractPane>();
    
    app->setScene(root);

That's interesting because I can see debug messages from my virtual functions in groupdatamodel (childcount() and data()),

but then got error in console: "Refference Error Can't find varialable friendsModel".

So as a Result I got 5 (cause my data model has 5 rows) empty strings at my ListView.

Please use plain text.
Developer
simon_hain
Posts: 15,872
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: What is correnct way to use custom GroupDataModel inside a qml?

In your StandardListItem you use ListItemData.first_name, not friendsModel
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
boytsov_s
Posts: 18
Registered: ‎01-31-2013
My Device: Dev Alpha
My Carrier: MobileTeleSystem

Re: What is correnct way to use custom GroupDataModel inside a qml?

Thank you.
Can you advice me: How can I make my ListView upToDate?
For example my GroupDataModel changes every 5 seconds when load Data from server.
Please use plain text.
Developer
simon_hain
Posts: 15,872
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: What is correnct way to use custom GroupDataModel inside a qml?

you use the methods that the datamodel offers, for example insertList (to add items) or clear/insertList to replace the contents.

As a side note: Could you mark the question as resolved if you found a solution and open a new thread for new questions? This helps other users to find answers for themselves.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.