当前位置:网站首页>Read and write INI file
Read and write INI file
2022-07-22 01:56:00 【Bug】
Reading and writing .ini file
zero , Preface
.ini File is the configuration file of the program , It is used to record historical information , Interface information , User operation, etc , Except, of course, ini Files can hold information , Other files can also be saved (json,txt,csv etc. ), If the data is relatively small and not frequently read and written, you can use the following formats to save .
Use ini file save : It does not need to open the file to operate .
Save in other ways : You need to open the file before reading and writing .
So in case of frequent operation ,ini Documents have great advantages .
operation ini Files need to use classes QSettings, The prototype is as follows :
QSettings setting(const QString &fileName,Format format,QObject* parent = 0);
Parameters 1: Profile name , If the file name does not exist , Automatically create ;
Parameters 2: be equal to QSetting::IniFormat when , Read and write *.ini Format of the configuration file ;
Parameters 3: You can default to ;
First, add a header file in the file header #include ,
One , Write
// establish QSettings Object and specify ini File path and set the format to ini
QSettings setting("./iniTest.ini", QSettings::IniFormat);
// Create the first group ( The first way to create a group )
setting.beginGroup("group1");
// Add key value pairs in the first group
setting.setValue("key1", "val1");
setting.setValue("key2", "val2");
setting.setValue("sameKay", "sameVal");
// Set the end of the current grouping
setting.endGroup();
// Add the second group and its key value pair ( The second way to create a group )
setting.setValue("group2/jian1", "zhi1");
setting.setValue("group2/jian2", "zhi4");
setting.setValue("group2/jian3", "zhi2");
setting.setValue("group2/sameKay", "sameZhi");
Two , read
Read the specified value , There is also a way to read all key values .
// establish QSettings Object and specify ini File path and set the format to ini
QSettings setting1("./iniTest.ini", QSettings::IniFormat);
qDebug() << " The second reading method ";
// obtain ini All groups in the file
QStringList groupList = setting1.childGroups();
// Specify to read a set of data
setting1.beginGroup(groupList[1]);
// Traverse the keys of the group
foreach (QString key, setting1.childKeys())
{
// Print out the current key value pair
qDebug() << key << setting1.value(key).toString();
}
total
This article is used for personal records
边栏推荐
- 动态规划例题——潜水员
- Common plug-ins of idea
- 谷歌展示 Chrome 浏览器图标废案,曾打算做成小火箭
- Local storage software system of local area network for data acquisition of electric meters in Enterprises
- Leetcode 206反转链表、3无重复字符的最长子串、912排序数组(快排)、215数组中的第k个最大元素、53最大子数组和、152乘积最大子数组
- ssh方式登录huawei设备
- 【数模/数学规划模型】
- VALDO2021——血管病变检测挑战赛之血管间隙分割(一)
- 【FreeRTOS】10 事件标志组
- Compare the market Taobao short video tools / software, and analyze the future trend of Taobao short video
猜你喜欢
【FreeRTOS】10 事件标志组
The Linux server installed the graphical interface, but failed to display the initialization graphical interface when installing the database
Apache Atlas 2.2版本安装
CRM concept: understand the concepts of leads, prospect, MQL and SQL
NepCTF2022 WP
huawei设置使用账号密码登录
TCP的滑动窗口、单例模式(懒汉饿汉)双检锁/双重校验锁(DCL,即 double-checked locking)
【扩展程序——猫抓1.0.15_网上的视频音频获取神器_安装教程加获取】
m基于中继协助的认知无线电频谱切换机制的matlab仿真分析
Aruba learning notes 03 Web UI -- Introduction to monitoring panel
随机推荐
URLEncode.encode(String,String) 和 new String(byte[],String) 的区别
huawei设置使用账号密码登录
Judgment of empty string in Oracle
Pytorch common code snippet collection
clip:learning transferable visual models from natural language supervision
Codeworks round 805 A-F problem solution
[鹏城杯 2022] baby_re
請問這是錶示mysql的binlog已經開啟嗎?
CRM concept: understand the concepts of leads, prospect, MQL and SQL
动态规划多重背包一维
sql中substr与substring函数用法
动态规矩-数组压缩优化
Idea 常用插件
Jugement des chaînes vides dans Oracle
Compare the market Taobao short video tools / software, and analyze the future trend of Taobao short video
使用修改为jmp指令的方式hook 32位函数
群晖7.1.0万兆网络实测
Dynamic programming multiple knapsack celebration (one dimension)
如何使用订单流分析工具(上)
Dynamic rules - array compression optimization