-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiniservice.cpp
73 lines (63 loc) · 1.73 KB
/
iniservice.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "iniservice.h"
INIService::INIService()
{
}
//连接配置文件
void INIService::connectINI(QString tFilePath)
{
QString fileFullName = QCoreApplication::applicationDirPath() + tFilePath;
activatedINI = new QSettings(fileFullName, QSettings::IniFormat);
//qDebug()<<"connectINI "<<fileFullName;
}
//查询键是否存在
bool INIService::keyExist(QString tSection, QString tKey)
{
bool resultExist;
QString initPath = "/"+tSection+"/"+tKey;
resultExist = (INIService::activatedINI->contains(initPath));
return resultExist;
}
//查询节点是否存在
bool INIService::sectionExist(QString tSection)
{
bool resultExist;
QString initPath = "/"+tSection;
resultExist = (INIService::activatedINI->contains(initPath));
return resultExist;
}
//获取键值
QString INIService::getValue(QString tSection, QString tKey)
{
QString resultValue;
QString initPath = "/"+tSection+"/"+tKey;
resultValue = activatedINI->value(initPath).toString();
return resultValue;
}
//获取节点内所有键
QStringList INIService::getAllValue(QString tSection)
{
QStringList resultList;
activatedINI->beginGroup(tSection);
resultList=activatedINI->allKeys();
activatedINI->endGroup();
return resultList;
}
//设置键值
void INIService::setValue(QString tSection, QString tKey, QString tValue)
{
activatedINI->beginGroup(tSection);
activatedINI->setValue(tKey,tValue);
activatedINI->endGroup();
}
//移除节点
void INIService::removeSection(QString tSection)
{
activatedINI->remove(tSection);
}
//移除键
void INIService::removeKey(QString tSection, QString tKey)
{
activatedINI->beginGroup(tSection);
activatedINI->remove(tKey);
activatedINI->endGroup();
}