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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 163
Registered: ‎01-30-2013
My Device: Blackberry 10 Simulator
Accepted Solution

Traverse QVariantList

[ Edited ]

Hi,

I have some JSON data which I import into a QVariantList, and using code below

I am trying to traverse this list and print out the items. But I have two issues:

 

   JsonDataAccess jda;
   QString path;
   path = QDir::currentPath() +
         "/app/native/assets/employees.json";
   QVariant list = jda.load(path);

   QVariantList temp = list.value<QVariantList>();
   for (int i = 0; i < temp.size(); ++i) {
       QString gStr = temp[i].toString();
       qDebug()<<"String Value: "<<gStr;
   }

 1. How to use qDebug properly in Momentics IDE? OS: Mac OS X; nothing gets printed even if I remove the gStr variable from that line

2. Is it correct way to traverse the QVariantList and print contents of its elements?

 

ps. the temp is correctly initialized I manage to fill a ListView using it later on.

 

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Traverse QVariantList

Hi,

1. Please check "Known limitations" section in SDK release notes, it contains information on setting up the logs:

https://developer.blackberry.com/cascades/download/releasenotes/

 

2. The code is correct. Another way to iterate the list:

 

foreach (QVariant v, temp)
{
  qDebug() << "String Value: " << v.toString() << "\n";
}

 

You might also want to add newline to flush the output otherwise last line can be lost on application crash.

 

Also foreach makes a copy of list before iterating. Qt performs lazy copying of data (copy-on-write), so this isn't very expensive and you can safely modify the container during iteration.


Andrey Fidrya, @zmeyc on twitter
Highlighted
Developer
Posts: 163
Registered: ‎01-30-2013
My Device: Blackberry 10 Simulator

Re: Traverse QVariantList

[ Edited ]

Yep, thanks. just one brief question. In my case it appears my "temp" is an array of 3 objects. Where clearly each object is a QVariantMap. Now I want to print out the contents of some keys (say "key1") in these QVariantMaps objects. do you have some code snippet that would do this? ps. I actually have issues converting the QVariantList item to a QVariantMap; I know how to print contents of a QVariantMap

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Traverse QVariantList

QVariantMap m = v.value<QVariantMap>();
qDebug() << m["key"].toString();

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 163
Registered: ‎01-30-2013
My Device: Blackberry 10 Simulator

Re: Traverse QVariantList

[ Edited ]

Yes I was about to write I had found a similar solution; but now my debug logging is not working.. a anyway thanks I will try to find smth.