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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Developer
trivedirujuta
Posts: 436
Registered: ‎10-06-2009
My Carrier: Vodafone
Accepted Solution

How to extract value from QVariantlist

Hi,

I was trying to understand quoteapp example to implement sqldata in my app. In that example they are passing whole qvariantlist into groupdatamodel and using it in listview. But I don't want to use listview and want to access particular column value of a table on a page. Can someone please guide me how to do it?

Rujuta Trivedi
Please use plain text.
Developer
Developer
klz
Posts: 127
Registered: ‎08-24-2011
My Carrier: MTS Ukraine

Re: How to extract value from QVariantlist

I will try to explain what I've done to understand how it works. So you have QVarint or QVariantList, right? So now print it in console using qDebug().

 

You will see something like that. 

 

QVariant(QVariantMap, QMap(("StationButton", QVariant(QString, "") ) ( "StationButtonSelected" ,  QVariant(QString, "") ) ( "StationIcon" ,  QVariant(QString, "0332.jpg") ) ( "StationName" ,  QVariant(QString, "JD Inside") ) ( "StationStreamURL" ,  QVariant(QVariantMap, QMap((".data", QVariant(QString, "http://www.panel-streaming.com/tunein.php/jdinside/playlist.pls") ) ( "type" ,  QVariant(QString, "pls") ) )  ) ) ( "StationURL" ,  QVariant(QString, "http://www.jdinside.com/") ) )  ) 

 

So now if I would like to get Station stream URL tyoe I need to do the following

 

QString currType = data.value<QVariantMap>().value("StationStreamURL").value<QVariantMap>().value("type").value<QString>();

 

As you can see first structure is QVariantMap, so we use data.velue<QVariantMap>() there to get it. Next is StationStreamUrl, than QVariantMap and than we can get type and convert it to QString. It's something like cabbage where you have to remove all layers.

 

Hope it helps. If not give me what structure you have and I will try to help you. 

 

Thanks. 

Thank you!
----------------------------
BlackBerry 10 Developer is looking for a job!
My Apps: Alchemy Game | Jam! | Traffic Signs: USA
My Blog: http://bb10pro.com
Please use plain text.
Developer
dridk
Posts: 91
Registered: ‎09-25-2012
My Carrier: free

Re: How to extract value from QVariantlist

You can make like this : 

 

QString value = datas.toMap().value("sources").toList().first().toMap().value("name").toString();

 

which return "sacha" for exemple : 

datas {

sources : [

1 : {

name : "sacha"

}

]

}

a lover of Qt
Please use plain text.
Developer
dridk
Posts: 91
Registered: ‎09-25-2012
My Carrier: free

Re: How to extract value from QVariantlist

And you can browse your datas like this : 

 

foreach ( QVariant item , datas.toList())

{

qDebug()<<item.type();

}

 

Another exemples , browse key maps : 

 

foreach ( QString key, datas.toMap().keys())

{

qDebug()<<key;

}

a lover of Qt
Please use plain text.
Developer
trivedirujuta
Posts: 436
Registered: ‎10-06-2009
My Carrier: Vodafone

Re: How to extract value from QVariantlist

Thanks all for helping me.@klz your solution explained exactly as I wanted.@dridk thanks a lot for the explaination

Rujuta Trivedi
Please use plain text.