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
Contributor
Scott56
Posts: 22
Registered: ‎01-05-2013
My Device: Dev Alpha
Accepted Solution

Listview won't display datamodel set from c++

I have a listview that retrieves a json file from a web service, and parses it into a datamodel (tried both GroupDataModel and QListDataModel). Thanks to some threads I've found here, I've managed to get the data into the data model, and associate it correctly to the listview. which I checked through debugging.

 

However; when I go back to QML, I'm not able to get the data to display.

 

My listview loots like this for the moment, but this is really just a stripped down version of what I want, since I'm trying to get it to work:

ListView {
                            objectName: "list"
                            listItemComponents: [
                                ListItemComponent {
                                    type: "item"
                                    Container {
                                        id: root
                                        WebImageView {
                                            url: ListItemData.image
                                        }
                                        Label {
                                            text: ListItemData.title
                                        }
                                    }
                                }
                            ]
                        }

 As for my c++ code, I uses the Twitter example found here as my base:

http://supportforums.blackberry.com/t5/Cascades-Development/Method-for-making-an-HTTP-style-request-...

 

For reference, if I try using QListDataModel, my maps ends up looking like this:

 QMap(("Description", QVariant(QString, "Description here") ) ( "image" ,  QVariant(QString, "https://image.com/image.jpg") ) ( "title" ,  QVariant(QString, "title") ) ) 

 

As I said, I can see the datamodel get associated with my list through list->setDataModel(model);, but it just isn't displaying anything. I'm sure it's something on the QML side that I'm getting wrong, but hopefully someone here can assist.

Developer
ekke
Posts: 1,595
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Listview won't display datamodel set from c++

don't know what you mean by "set the datamodel from C++"

I had problems to set a groupDataModel from C++

so I'm doing it this way:

 

attach datamodel in qml:

attachedObjects: [
                GroupDataModel {
                    id: carDriverWorkOrderDataModel
                    objectName: "carDriverWorkOrderDataModel"

 reference from ListView:

ListView {
                id: carDriverWorkOrderList
                objectName: "carDriverWorkOrderList"
                dataModel: carDriverWorkOrderDataModel

 and then from C++ not setting the datamodel on ListView, only clear() and insert(), per ex:

mCarDriverWorkOrderDataModel = Application::instance()->scene()->findChild<GroupDataModel*>("carDriverWorkOrderDataModel");
if (mCarDriverWorkOrderDataModel) {
	mCarDriverWorkOrderDataModel->clear();
	........
mCarDriverWorkOrderDataModel->insert(xxxxx); ......

 

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Developer
sbeeckma
Posts: 20
Registered: ‎10-09-2010
My Device: Bold 9700

Re: Listview won't display datamodel set from c++

Indeed, GroupDataModel is not easy. Watch out for null pointers and invalid sorting keys. But try perhaps first: add a dataModel to your QML code, which your C++ code will then later replace by calling list->setDataModel(model);.

Contributor
Scott56
Posts: 22
Registered: ‎01-05-2013
My Device: Dev Alpha

Re: Listview won't display datamodel set from c++

I just tried doing it the way ekke recommended, but still nothing is showing up. If it helps, this is what is being inserted into the GroupDataModel.

 

QMap(("Description", QVariant(QString, "Description Text") ) ( "Image" ,  QVariant(QString, "https://image.com/image.jpg") ) ( "Title" ,  QVariant(QString, "Title Text") )

 

 

 

Developer
strobejb
Posts: 287
Registered: ‎10-15-2012
My Device: bb10 developer

Re: Listview won't display datamodel set from c++

Make sure your datamodel is returning the correct item type for the list items.

In your QML, look at overriding the itemType() callback function to make sure it returns the string "item" appropriately
Contributor
Scott56
Posts: 22
Registered: ‎01-05-2013
My Device: Dev Alpha

Re: Listview won't display datamodel set from c++

I tried that before, with the same result; however there is a chance that I'm not returning the right item type.

 

From what I could tell, that function determines whether the listview item is a header or item, no? I don't want any headers to be returned.

 

Based on the code I've provided, how would I go about implementing that function if I don't want any headers returned?

Contributor
Scott56
Posts: 22
Registered: ‎01-05-2013
My Device: Dev Alpha

Re: Listview won't display datamodel set from c++

So I figured out my issue while working on another part of the app.

 

Unlike the Twitter example I provided, I wasn't using a global variable for *root. I believe when I first started with that example, that part was giving me issues, so I used local variables. Because of this, my app was creating the root object in both the initialization, and the "GetTimeline" method.

 

Once I made fixed it to be global, the list populated.

 

Thanks for your help on this everyone.