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
Sumitava_Datta
Posts: 83
Registered: ‎02-18-2013
My Device: Blackberry 10
Accepted Solution

In Group data model when list count 1 then data does not show in list field

[ Edited ]

I have a Xml file contacts.xml ,that content is below...

 

<contacts version="1.0">
<contact>
<id>1</id>
<title>Sr. Editor</title>
<firstname>Mike</firstname>
<lastname>Chepesky</lastname>
<phonenumber></phonenumber>
</contact>
</contacts>

 

In cpp I just do below code

 

GroupDataModel *model = new GroupDataModel();
XmlDataAccess xda;
QVariant list = xda.load(
QDir::currentPath() + "/app/native/assets/contacts.xml",
"/contacts/contact");

model->insertList(list.value<QVariantList>());

QStringList key;
key << "id";
model->setSortingKeys(key);
model->setSortedAscending(FALSE);

listView->setDataModel(model);

 

When that XML have more then one chilled then data show in listview but when one chilled the data does not show.

Please help me...... 

 

Mod Edit: Removed personal information to comply with Community Guidelines and Terms and Conditions of Use.

Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: In Group data model when list count 1 then data does not show in list field

[ Edited ]

I'm not 100% sure, but I think if there's only 1 element it may be treating it as a map. So, something like this may be needed (untested):

 

QVariant list = xda.load(
QDir::currentPath() + "/app/native/assets/contacts.xml",
"/contacts/contact");

QVariantList l = list.value<QVariantList>();
if (l.isNull())
  model->insert(list.value<QVariantMap>());
else
  model->insertList(list.value<QVariantList>());

Please tell if it works. If so, the docs should be updated to include this case.

 


Andrey Fidrya, @zmeyc on twitter
BlackBerry Development Advisor
sabdelsayed
Posts: 249
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10

Re: In Group data model when list count 1 then data does not show in list field

[ Edited ]

Hi Sumitava_Datta,

 

Please report this issue in jira (Developer Issue Tracker). 

 

I confirm that Zmey's solution works. I have tried it myself and it does indeed provide a workaround to this bug. Just use isEmpty() instead of isNull(), which is not recognized as a valid QVariantList function.

 

QVariant list = xda.load(
QDir::currentPath() + "/app/native/assets/contacts.xml",
"/contacts/contact");

QVariantList l = list.value<QVariantList>();
if (l.isEmpty())
  model->insert(list.value<QVariantMap>());
else
  model->insertList(list.value<QVariantList>());

 

 

@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Developer
Sumitava_Datta
Posts: 83
Registered: ‎02-18-2013
My Device: Blackberry 10

Re: In Group data model when list count 1 then data does not show in list field

Hi sabdelsayed,

 

Thanks for your reply . Can you provide the link to post on jira?

BlackBerry Development Advisor
sabdelsayed
Posts: 249
Registered: ‎08-17-2012
My Device: BlackBerry Z10 and Q10

Re: In Group data model when list count 1 then data does not show in list field

Link to jira: https://www.blackberry.com/jira/secure/Dashboard.jspa
@SamarAbdelsayed

Did this answer your question? Please accept post as solution.
Please refrain from posting new questions in solved threads.
Found a bug? Report it using the Issue Tracker
Developer
Sumitava_Datta
Posts: 83
Registered: ‎02-18-2013
My Device: Blackberry 10

Re: In Group data model when list count 1 then data does not show in list field

Thanks...........