-
Notifications
You must be signed in to change notification settings - Fork 360
/
mainwindow.cpp
83 lines (75 loc) · 2.84 KB
/
mainwindow.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
74
75
76
77
78
79
80
81
82
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QCoreApplication>
#include <QSettings>
#include <QDateTime>
#include <QFileInfo>
#include <QMetaType>
#include <QDebug>
#include "EasyIni.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->myWrite,&QPushButton::clicked,this,[this]{
using namespace Tool;
const QString path=qApp->applicationDirPath()+"/ini/"+ui->myEdit->text();
qDebug()<<"write"<<path;
EasyIni ini(path,EasyIni::WriteOnly);
ini.setValue("AA","AA","测试");
ini.setValue("BB","AA","测试");
ini.setValue("BB","BB",1);
ini.setValue("BB","CC",true);
ini.setValue("中文组","中文键","中文值");
});
connect(ui->myRead,&QPushButton::clicked,this,[this]{
using namespace Tool;
const QString path=qApp->applicationDirPath()+"/ini/"+ui->myEdit->text();
qDebug()<<"read"<<path;
EasyIni ini(path,EasyIni::ReadOnly);
ini.dumpInfo();
qDebug()<<ini.groups();
qDebug()<<ini.keys("AA");
qDebug()<<ini.keys("A");
qDebug()<<ini.value("BB","AA");
qDebug()<<ini.value("BB","BB");
qDebug()<<ini.value("BB","CC");
qDebug()<<ini.value("BB","QWER");
ini.setValue("BB","CC",true);
ini.setValue("BB","QWER",12345);
qDebug()<<ini.value("BB","CC");
qDebug()<<ini.value("BB","QWER");
qDebug()<<ini.value("BB","QWER2");
});
connect(ui->btnWrite,&QPushButton::clicked,this,[this]{
const QString path=qApp->applicationDirPath()+"/ini/"+ui->lineEdit->text();
QSettings setting(path,QSettings::IniFormat);
setting.setIniCodec("utf-8");
qDebug()<<"write"<<path;
setting.setValue("BB/AA","测试");
setting.setValue("BB/BB",true);
setting.setValue("BB/CC",123.7);
//保存ini会把中文写成unicode:"%U4E2D%U6587"
//但是读取ini时,手动输入的中文是不能正常读取的,
//且保存ini的时候会修改掉手写中文的格式,如中文变成"%E4%B8%AD%E6%96%87"
setting.setValue("中文/中文","测试中文");
});
connect(ui->btnRead,&QPushButton::clicked,this,[this]{
const QString path=qApp->applicationDirPath()+"/ini/"+ui->lineEdit->text();
QFileInfo info(path);
qDebug()<<info.lastModified()<<info.metadataChangeTime();
QSettings setting(path,QSettings::IniFormat);
setting.setIniCodec("utf-8");
qDebug()<<"read"<<path;
qDebug()<<setting.value("BB/AA");
qDebug()<<setting.value("BB/BB");
qDebug()<<setting.value("BB/CC");
qDebug()<<setting.value("None/AA");
});
//qDebug()<<QVariant("false").toBool()<<QVariant("true").toBool();
}
MainWindow::~MainWindow()
{
delete ui;
}