12-30-2012 01:17 PM
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?
Solved! Go to Solution.
12-30-2012 03:02 PM
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.
12-30-2012 09:18 PM
You can make like this :
QString value = datas.toMap().value("sources").toList().first().to
which return "sacha" for exemple :
datas {
sources : [
1 : {
name : "sacha"
}
]
}
12-30-2012 09:20 PM
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;
}
12-31-2012 02:00 AM
Thanks all for helping me.@klz your solution explained exactly as I wanted.@dridk thanks a lot for the explaination