[SailfishDevel] How to handle app settings?
Bob Jelica
sailfish at jelica.se
Sat Dec 28 18:40:53 UTC 2013
I use a QML-enabled QSettings wrapper created by Nokia at some point.
Here’s the download link: https://dl.dropboxusercontent.com/u/10015284/qml_settings/settings.cpp and https://dl.dropboxusercontent.com/u/10015284/qml_settings/settings.h
Put those into your project, then register it in your main.cpp (or PROJECTNAME.cpp) like this:
Settings settings;
//create the root context and set the context properties
QQmlContext *rootContext = view->rootContext();
//register our c++ modules for usage in QML
rootContext->setContextProperty("settings", &settings);
Now you have a ”settings” object available everywhere in your QML/JS.
Usage:
Save an object: settings.setSetting(”name”, value);
Read a saved object: settings.setting(”name”);
Works like a charm ;)
//b0bben
On 28 Dec 2013, at 19:06, Artem Marchenko <artem.marchenko at gmail.com> wrote:
> Hi there
>
> I believe somebody was posting to IRC a link to a QML wrapper for QSettings done as a part of some nemo project.
>
> If you want something QML that works, I use this pure QML LocalStorage approach for the last couple of years fine - https://github.com/amarchen/Wikipedia/blob/master/src/qml/components/DbDictionary.qml
>
> Nowadays I would have started with wrapping QSettings though (and pull requests to Wikipedia for changing LocalStorage use into QSettings wrapper are welcome :))
>
> Best regards,
> Artem.
>
>
>
> On Sat, Dec 28, 2013 at 7:45 PM, Kimmo Lindholm <Kimmo.Lindholm at eke.fi> wrote:
> I did it like this with QSettings, it works. I don't know is it the correct way... (comments anyone?)
>
> introduce me in main()
> QCoreApplication::setOrganizationDomain("diibadaaba");
> QCoreApplication::setOrganizationName("diibadaaba ");
> QCoreApplication::setApplicationName("badbreath");
> QCoreApplication::setApplicationVersion("0.1-1");
>
> read
> QSettings settings;
> m_mySetting = settings.value("mySetting", "").toString();
>
> write
> QSettings settings;
> settings.setValue("mySetting", m_mySetting);
>
> -kimmo
>
>
> _______________________________________________
> SailfishOS.org Devel mailing list
>
>
>
> --
> Artem Marchenko
> http://agilesoftwaredevelopment.com
> http://twitter.com/AgileArtem
> _______________________________________________
> SailfishOS.org Devel mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20131228/1c011ef2/attachment.html>
More information about the Devel
mailing list