Skip to content

Instantly share code, notes, and snippets.

@kovrov
Created November 20, 2013 19:04
Show Gist options
  • Save kovrov/7569004 to your computer and use it in GitHub Desktop.
Save kovrov/7569004 to your computer and use it in GitHub Desktop.
QML Settings
#include "qmlsettings.h"
#include <QtCore/QSettings>
QmlSettings::QmlSettings(QObject *parent) :
QQmlPropertyMap (parent),
m_settings (new QSettings(this))
{
m_settings->beginGroup("qml");
foreach (const auto &key, m_settings->allKeys()) {
insert(key, m_settings->value(key));
}
}
QmlSettings::~QmlSettings()
{
m_settings->endGroup();
m_settings->sync();
}
QVariant QmlSettings::updateValue(const QString &key, const QVariant &input)
{
m_settings->setValue(key, input);
return QQmlPropertyMap::updateValue(key, input);
}
#ifndef QMLSETTINGS_H
#define QMLSETTINGS_H
#include <QtCore/QPointer>
#include <QtQml/QQmlPropertyMap>
class QSettings;
class QmlSettings : public QQmlPropertyMap
{
Q_OBJECT
public:
explicit QmlSettings(QObject *parent = 0);
~QmlSettings();
protected:
QVariant updateValue(const QString &key, const QVariant &input);
private:
QPointer<QSettings> m_settings;
};
#endif // QMLSETTINGS_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment