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: 19
Registered: ‎03-06-2014
My Device: blackberry z10 stl100-3
My Carrier: n/a
Accepted Solution

Extract value from QVariantMap

I've read in an xml file with XmlDataAccess then turned it into a QVariantMap and have spent the last couple of hours in frustration trying to extract basic data from it.

 

Here's the QDebug from the QVariantMap:

 

QMap(
(".root", QVariant(QString, "NewInstallApp_Response"))
( "Act_btnAct" , QVariant(QString, "Activates") )
( "Act_lblErr" , QVariant(QString, "Please enter a valid 16 character activation codes") )
( "Act_lblTitle" , QVariant(QString, "Enter Activation Codes") )
( "ErrNumber" , QVariant(QString, "0") )
( "Message" , QVariant(QString, "") )
( "Status" , QVariant(QString, "APPROVED") )
( "UpdatePending" , QVariant(QString, "true") )
( "btnCancel" , QVariant(QString, "Cancels") ) ...

 

How would I grab the value for ErrNumber?

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Extract value from QVariantMap

map.value("errNumber").toString();


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Extract value from QVariantMap

You retrieve values from QMaps by doing map[key]

 

So, it would be map["ErrNumber"], and you would get a QVariant back that you could turn into a QString.

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Extract value from QVariantMap

[ Edited ]

Use toInt() to get an integer or you can use JavaScript's parseInt() to convert to a number...

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.