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: 528
Registered: ‎10-06-2009
My Device: 9800,BB Dev Alpha,z10 limited edition
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
Highlighted
Developer
Developer
Posts: 132
Registered: ‎08-24-2011
My Device: Z10 LE + Playbook
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!
----------------------------
My Apps: Alchemy Game | Image Resizer | Jam! | Traffic Signs: USA | Radio Record
My Blog: http://bb10pro.com
Developer
Posts: 91
Registered: ‎09-25-2012
My Device: bb10 alpha
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
Developer
Posts: 91
Registered: ‎09-25-2012
My Device: bb10 alpha
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
Developer
Posts: 528
Registered: ‎10-06-2009
My Device: 9800,BB Dev Alpha,z10 limited edition
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