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
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

QListDataModel: anyone gotten it to work or seen any samples?

Hey everyone - has anyone built anything with QListDataModel yet? Im having some issues with it and the QML ListItemComponents not getting the ListItem property set for each component, its just null. Does anyone have working samples of this type or anyone run into an issue like this?

Like all of my posts
Developer
Posts: 188
Registered: ‎01-27-2012
My Device: playbook
My Carrier: ...

Re: QListDataModel: anyone gotten it to work or seen any samples?

Here is the documentation, it has some good examples right in it. http://doc-snapshot.qt-project.org/4.8/qdeclarativemodels.html

Maybe post a snippet of your model  code and someone can point you in the right direction.

Cheers,

Jon

Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: QListDataModel: anyone gotten it to work or seen any samples?

That's the standard Qt data model stuff though, I'm working with the cascades ListView and QListDataModel though (which is maybe why we need a cascades forum). I've changed all my stuff over to GroupDataModel and the QML now has a defined property of ListItem. All the C++ code was basically the same to fill the model with data, there could be a bug in the QListDataModel here. I even tried the model with QString items in the list and still had the same problems, eliminating any chance that it was my data structure that was screwing things up.
Like all of my posts
Retired
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: QListDataModel: anyone gotten it to work or seen any samples?

Could you post a sample which demonstrates the issue you are seeing?

Garett
@garettBeuk
--
Goodbye everybody!
Contributor
Posts: 13
Registered: ‎02-17-2012
My Device: Torch 9600, Playbook
My Carrier: Rogers

Re: QListDataModel: anyone gotten it to work or seen any samples?

I converted my QStandardItemModel to a GroupDataModel which works perfectly in my QML application. If you don't need the header sections you can set the "grouping" property to "ItemGrouping::None".

 

I did not have any success when I tried QListDataModel, but I didn't try too hard before converting to the GroupDataModel. This may not be much help if you have a really complicated model to convert, but for my simple model it was quite effective.

Developer
Posts: 137
Registered: ‎09-30-2009
My Device: Torch 9800

Re: QListDataModel: anyone gotten it to work or seen any samples?

Hi

I was also having difficulty making QListDataModel working.

 

I just got it working. The list only shows a text item though This is the proces I followed

 

i first inserted a ListView in my qml 

 

ListView {
                    objectName: "resultlistview"
                }

 Then my application uses curl to get a feed from network and then uses json parser to parse the response. I showed the title of the items in the list view using QListDataModel which uses QString data type.

 

QListDataModel<QString> *listDataModel;
listDataModel = new QListDataModel<QString>();

 in the json parser for each text item i want to show i used this code to append an item to the data model

//my value->vu.str.value is a const char*
QString value1 =  QString::fromLatin1(value->vu.str.value);
listDataModel->append(value1);

 Now when parsing is complete. I use below code to set my data model to list view

ListView *mListView = root->findChild<ListView*>("resultlistview");
mListView->setDataModel(listDataModel);

 That showed me the list in the UI. I hope it will be helpful for others.

----------------------
Press like if you find a message helpful
---------
Highlighted
Retired
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: QListDataModel: anyone gotten it to work or seen any samples?

@kylefowler

 

I just did some digging into this and found that if you are not using a data type known to QML then it will be unable to retrieve the ListItemData. As such there are 2 approaches:

1) Declare your data type used in your QListDataModel so the QML side knows what it is being passed

2) Instead of declaring your QListDataModel with a custom data type, declare it with QObject (assuming your data type extends QObject) which is known already on the QML side

Garett
@garettBeuk
--
Goodbye everybody!