Created
November 20, 2013 19:04
-
-
Save kovrov/7569004 to your computer and use it in GitHub Desktop.
QML Settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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