Created
September 23, 2013 09:45
-
-
Save Kernald/6668425 to your computer and use it in GitHub Desktop.
Qt settings handler, invokable from QML
This file contains 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 "settings.hpp" | |
#include <QtCore/QSettings> | |
QVariant Settings::getValueFor(const QString &objectName, const QVariant &defaultValue) { | |
QSettings settings; | |
// If no value has been saved, return the default value | |
if (settings.value(objectName).isNull()) { | |
return defaultValue; | |
} | |
// Otherwise, return the value stored in the settings object | |
return settings.value(objectName); | |
} | |
void Settings::saveValueFor(const QString &objectName, const QVariant &inputValue) { | |
// A new value is saved to the application settings object | |
QSettings settings; | |
settings.setValue(objectName, inputValue); | |
} |
This file contains 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 __SETTINGS_HPP__ | |
#define __SETTINGS_HPP__ | |
#include <QtCore/QObject> | |
#include <QtCore/QVariant> | |
class Settings : public QObject { | |
Q_OBJECT | |
public: | |
Q_INVOKABLE static QVariant getValueFor(const QString &objectName, const QVariant &defaultValue); | |
Q_INVOKABLE static void saveValueFor(const QString &objectName, const QVariant &inputValue); | |
}; | |
#endif // __SETTINGS_HPP__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment