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: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile
Accepted Solution

QSettings used to save Vector?

[ Edited ]

Would QSettings be able to handle more than just basic types of data?

 

For instance if I have a Vector filled with instances of a customer class that may include data types such as QStrings, integers, QDateTime, etc is there a way to save all these elements together at one time. The reason being is I will have multiple instances of this class in a vector therefore I need all the data in each class stored together as 1 so it can be loaded as 1.

 

Would QSettings be able to handle this?

Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: QSettings used to save Vector?

no, you would have to simplify the data first. or use sqlite (where you would have to serialize as well though)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

Re: QSettings used to save Vector?

Hmm okay, what do you think the best solution would be?

E.g of the data I need to store

class Profile{
QString name;
int type;
QDateTime time;
}

Then I may have 1 - 10 instances of these at any time inside of a vector.
Developer
Posts: 285
Registered: ‎08-06-2010
My Device: Z10

Re: QSettings used to save Vector?

Just serialize your values as a QVariantMap.



Follow me on twitter @RileyGB - https://twitter.com/RileyGB
View my BB10 OpenSource projects - https://github.com/RileyGB/BlackBerry10-Samples
Developer
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

Re: QSettings used to save Vector?

Thanks for the tip. I took a look at the documentation and it looks like it might be useful, see below.

// Create QVariantMap objects for each city
QVariantMap firstCity;
QVariantMap secondCity;
QVariantMap thirdCity;

// Populate the QVariantMap objects
firstCity["cityName"] = "Waterloo"; firstCity["countryName"] = "Canada";
secondCity["cityName"] = "Rome"; secondCity["countryName"] = "Italy";
thirdCity["cityName"] = "Barcelona"; thirdCity["countryName"] = "Spain";

However I do not have a static number of cities (using this example). So I am assuming you are telling me to serialize the values as a QVariantMap and then store them in QSettings, correct?

I'm not sure how I would dynamically store different amounts of this serialized data though.
Developer
Posts: 285
Registered: ‎08-06-2010
My Device: Z10

Re: QSettings used to save Vector?

[ Edited ]

You would store the cities inside of a QVariantList. 

 

Your model could be something to the effect of 

 

{

"CityCountryCollection":     [

       {

              "cityName": "Ottawa",

              "countryName": "Canada"

       },

       {

              "cityName": "Barcelona",

              "countryName": "Spain"

       }

     ]

}

 

Where { } represent QVariantMaps and [ ] Represent QVariantLists.



Follow me on twitter @RileyGB - https://twitter.com/RileyGB
View my BB10 OpenSource projects - https://github.com/RileyGB/BlackBerry10-Samples
Developer
Posts: 374
Registered: ‎02-12-2011
My Device: Bold 9780
My Carrier: Wind Mobile

Re: QSettings used to save Vector?

Thanks.

I stored the actual data in a QVariantMap like the example in my post. Then I added them to a QVariantList and then put the QVariantList directly into the QSettings.

Seems to be working great.

Thanks again