-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsettings.cpp
56 lines (48 loc) · 1.4 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "settings.h"
#include <QSettings>
#include <QDebug>
Settings::Settings(QObject *parent) :
QObject(parent)
{
}
Settings::~Settings()
{
qDebug() << "[QML] settings destructor";
}
void Settings::sync()
{
QProcess p(this);
qDebug() << "executing synch";
p.start("sync");
QByteArray data;
while(p.waitForReadyRead())
data.append(p.readAll());
}
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() << "[QML] set setting key: " << key << ":" << value ;
settings.endGroup();
settings.sync();
}
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() << "[QML] 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() << "[QML] remove setting key: " << key;
settings.endGroup();
settings.sync();
}