Work with QVariantMap

Posted this question 2 weeks ago here and on the QT forums and got no response

I am desperate and have not made any progress on what seems to be a relatively simple problem.

I managed to simplify a QVariantMap to this:

QMap(
    ("_MoreStuff", QVariant
    (QVariantList,
        (QVariant
        (QVariantMap, QMap
             (("stuffID", QVariant(QString, "1") )
             ( "stuffValue" ,  QVariant(QString, "I want this value 1") ) )
                ) ,
         QVariant
          (QVariantMap, QMap
              (("stuffID", QVariant(QString, "2") )
               ( "stuffValue" ,  QVariant(QString, "I want this value 2") ) )
                ) ,
          QVariant(
           QVariantMap, QMap
            (("stuffID", QVariant(QString, "3") )
            ( "stuffValue" ,  QVariant(QString, "I want this value 3") ) )
                ) ...

I need to browse this list and extract the stuffID and StuffValue

I tried a bunch of different loops like this:

QVariant stuff;
for (iter = datamap.begin () QVariantMap::const_iterator; iter! = datamap.end (); ++ iter) {}
qDebug()< "keys="" are:="" "="">< iter.key()="">< "values="" are:="" "=""><>
Stuff = iter.value ();
}
foreach (QVariant item, stuff.toList ())
{
qDebug()< "listing="" stuff="" items:="">
qDebug()<>
}

and the best I have is looping through the thing whole but only get empty quotes "" or nothing at all.

Literally he understood 5 minutes after posting this, lol.

QVariant stuff;
                for(QVariantMap::const_iterator iter = datamap.begin(); iter != datamap.end(); ++iter) {
                  qDebug() << "Keys Are: " << iter.key() << "Values Are: " << iter.value();
                  stuff = iter.value();
                   //datalist = stuff.toMap();
                }
                foreach ( QVariant item , stuff.toList())
                {
                    //qDebug() << "listing stuff items: ";
                    QVariantMap mapstuff = item.toMap();
                    int i = 0;
                    QString itemkey = "";
                    QString itemValue = "";
                    for(QVariantMap::const_iterator iter = mapstuff.begin(); iter != mapstuff.end(); ++iter) {
                        //qDebug() << "Keys Are: " << iter.key() << "Values Are: " << iter.value();
                        if (i == 0){
                            itemkey = iter.value().toString();
                        }else{
                            itemValue = iter.value().toString();
                        }
                        i++;
                    }
                    qDebug() << "final key/values: " << itemkey << "->" << itemValue;

                }

It's spitting the QVariant list, then go through each element of the list as a QVariantMap

my output looks like this:

final key/values :-> '1' ' I want that this value 1 "»

final key/values: '2'-> ' I want that this value 2 ".

final key/values :-> '3' ' I want that this value 3 "»

I'm sure there is an easier way to do this, but I'm just happy that it works.

Tags: BlackBerry Developers

Similar Questions

Maybe you are looking for