-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsettings.cpp
42 lines (37 loc) · 1.14 KB
/
settings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "settings.h"
#include <QSettings>
#include <QDebug>
Settings::Settings(QObject *parent) :
QObject(parent)
{
}
Settings::~Settings()
{
qDebug() << "settings destructor";
}
void Settings::setValue(const QString &key, const QVariant &value)
{
QSettings settings(APPLICATION_SETTINGS_FILE,QSettings::NativeFormat);
settings.beginGroup(APPLICATION_SETTINGS_SECTION);
settings.setValue(key, value);
qDebug() << "set setting key: " << key << ":" << value ;
settings.endGroup();
}
QVariant Settings::getValue(const QString &key, const QVariant &defaultValue) const
{
QVariant val;
QSettings settings(APPLICATION_SETTINGS_FILE,QSettings::NativeFormat);
settings.beginGroup(APPLICATION_SETTINGS_SECTION);
val = settings.value(key, defaultValue);
qDebug() << "get setting key: " << key << ":" << val;
settings.endGroup();
return val;
}
void Settings::remove(const QString &key)
{
QSettings settings(APPLICATION_SETTINGS_FILE,QSettings::NativeFormat);
settings.beginGroup(APPLICATION_SETTINGS_SECTION);
settings.remove(key);
qDebug() << "remove setting key: " << key;
settings.endGroup();
}