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
Highlighted
Developer
Posts: 33
Registered: ‎08-28-2013
My Device: non-BlackBerry user
My Carrier: TURKCELL
Accepted Solution

Saving QMap to QSettings and retrieving it back

[ Edited ]

Hi again. I am kinda in a desperate situation. I have a flightList map which is

QMap< QString, QMap<QString, QString> > flightListMap;

 Now I need to store this map and retrieve it back when application opens.I learnt that QSettings serves this purpose. What I did was below:

void ApplicationUI::saveSettings(QMap< QString, QMap<QString, QString> > flightListMap) {
QSettings settings("myComp", "myApp"); settings.setValue("flightList", flightListMap);
}

 

 But apparently since I am asking for your help, it didnt work (: The error that I got is:

../src/applicationui.cpp:113:63: error: no matching function for call to 'QSettings::setValue(const char [19], QMap<QString, QMap<QString, QString> >&)'

 I beg for your help.
Thank you !

Developer
Posts: 33
Registered: ‎08-28-2013
My Device: non-BlackBerry user
My Carrier: TURKCELL

Re: Saving QMap to QSettings and retrieving it back

All right, I got it work! I am writing down so it might help other people as well because I was about to crash my laptop...
Things I should have done were;

1) Writing this on top .cpp file

typedef QMap< QString, QMap<QString, QString> > templatemap;
Q_DECLARE_METATYPE(templatemap);

 2) Registering them during run-time as well

    qRegisterMetaType<QMap< QString, QMap<QString, QString> > >("templatemap");
    qRegisterMetaTypeStreamOperators<QMap< QString, QMap<QString, QString> > >("templatemap");

 3) Finally, retrieving it correctly (:

QVariant qv = settings.value("flightList");
    QMap< QString, QMap<QString, QString> > myMap = qv.value< QMap< QString, QMap<QString, QString> > >();

 

Thanks for the information written in this link> http://developer.nokia.com/community/wiki/Saving_custom_structures_and_classes_to_QSettings

 

Hope I could be able to help the people save some time who are stuck like me (: