Qt对ini文件的读写
研究了以下Qt下ini文件的读写,不废话,上干货。
写入ini文件
WriteIni.cpp
void WriteIni::writeSettings()
{
QSettings settings("config.ini", QSettings::IniFormat); // 当前目录的INI文件 settings.beginGroup("mountinfo");
settings.setValue("mount",);
settings.endGroup(); settings.beginGroup("v");
settings.setValue("v1",14.2);
settings.setValue("v2",14.3);
settings.setValue("v3",14.4);
settings.setValue("v4",14.5);
settings.setValue("v5",14.6);
settings.setValue("v6",14.8);
settings.endGroup(); settings.beginGroup("a");
settings.setValue("a1",2.0);
settings.setValue("a2",2.1);
settings.setValue("a3",2.2);
settings.setValue("a4",2.3);
settings.setValue("a5",2.4);
settings.setValue("a6",2.5);
settings.endGroup(); settings.beginGroup("p");
settings.setValue("p1",);
settings.setValue("p2",);
settings.setValue("p3",);
settings.setValue("p4",);
settings.setValue("p5",);
settings.setValue("p6",);
settings.endGroup(); settings.beginGroup("j");
settings.setValue("j1",4.8);
settings.setValue("j2",4.9);
settings.setValue("j3",4.7);
settings.setValue("j4",4.6);
settings.setValue("j5",4.5);
settings.setValue("j6",4.4);
settings.endGroup();
}
读取ini文件
ReadConfig.cpp
void GetConfigIni::getConfigMount()
{
QVariant strConfigValue;
QString strConfigGroup = "";
QString strConfigKey = ""; QString strfile; //strfile = QDir::currentPath();//QCoreApplication::applicationDirPath(); QString fileName = "config.ini"; strfile += fileName;
QSettings user_cfg(strfile,QSettings::IniFormat);
user_cfg.setIniCodec("UTF-8");
strConfigGroup = tr("mountinfo");
user_cfg.beginGroup(strConfigGroup); strConfigKey = "mount";
strConfigValue = user_cfg.value(strConfigKey); int Mount = strConfigValue.toInt(); qDebug()<<"mount*************"<<Mount<<endl; user_cfg.endGroup(); strConfigGroup = tr("v");
user_cfg.beginGroup(strConfigGroup); strConfigKey = "v1";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "v1=*********"<<strConfigValue; strConfigKey = "v2";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "v2=*********"<<strConfigValue; strConfigKey = "v3";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "v3=*********"<<strConfigValue; strConfigKey = "v4";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "v4=*********"<<strConfigValue; strConfigKey = "v5";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "v5=*********"<<strConfigValue; strConfigKey = "v6";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "v6=*********"<<strConfigValue; user_cfg.endGroup(); strConfigGroup = tr("a");
user_cfg.beginGroup(strConfigGroup); strConfigKey = "a1";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "a1=*********"<<strConfigValue; strConfigKey = "a2";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "a2=*********"<<strConfigValue; strConfigKey = "a3";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "a3=*********"<<strConfigValue; strConfigKey = "a4";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "a4=*********"<<strConfigValue; strConfigKey = "a5";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "a5=*********"<<strConfigValue; strConfigKey = "a6";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "a6=*********"<<strConfigValue; user_cfg.endGroup(); strConfigGroup = tr("p");
user_cfg.beginGroup(strConfigGroup); strConfigKey = "p1";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "p1=*********"<<strConfigValue; strConfigKey = "p2";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "p2=*********"<<strConfigValue; strConfigKey = "p3";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "p3=*********"<<strConfigValue; strConfigKey = "p4";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "p4=*********"<<strConfigValue; strConfigKey = "p5";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "p5=*********"<<strConfigValue; strConfigKey = "p6";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "p6=*********"<<strConfigValue; user_cfg.endGroup(); strConfigGroup = tr("j");
user_cfg.beginGroup(strConfigGroup); strConfigKey = "j1";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "j1=*********"<<strConfigValue; strConfigKey = "j2";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "j2=*********"<<strConfigValue; strConfigKey = "j3";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "j3=*********"<<strConfigValue; strConfigKey = "j4";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "j4=*********"<<strConfigValue; strConfigKey = "j5";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "j5=*********"<<strConfigValue; strConfigKey = "j6";
strConfigValue = user_cfg.value(strConfigKey);
qDebug() << "j6=*********"<<strConfigValue; user_cfg.endGroup(); }
ini文件
config.ini
[mountinfo]
mount= [v]
v1=14.2
v2=14.3
v3=14.4
v4=14.5
v5=14.6
v6=14.8 [a]
a1=
a2=2.1
a3=2.2
a4=2.3
a5=2.4
a6=2.5 [p]
p1=
p2=
p3=
p4=
p5=
p6= [j]
j1=4.8
j2=4.9
j3=4.7
j4=4.6
j5=4.5
j6=4.4
以上代码通过编译测试。
Qt对ini文件的读写的更多相关文章
- INI 文件的读写操作
在C#中对INI文件进行读写操作,在此要引入using System.Runtime.InteropServices; 命名空间,具体方法如下: #region 变量 private static r ...
- 安卓读写INI文件 安卓读写INI文件
安卓读写INI文件 安卓读写INI文件 uses System.IoUtils procedure TForm1.Button1Click(Sender: TObject);varIniFile: ...
- Qt对xml文件的读写
最近研究了一下qt下对xml文件的读写,小计一下,成为自己的知识. main函数调用: #include <QApplication> #include "readconfig. ...
- WPF操作ini 文件的读写示例
/// <summary> /// IniFiles 的摘要说明. /// 示例文件路径:C:\file.ini /// [Server] //[*] 表示缓存区 /// name=loc ...
- INI文件的读写
public class INIoperation { string inipath = Utils.GetMapPath("/Integration/Sync/set.ini") ...
- asp.net 操作INI文件的读写,读写操作本地ini配置文件
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...
- Qt读写ini文件
一 背景 1 ini文件介绍 .ini 文件是Initialization File的缩写,即初始化文件. 除了windows现在很多其他操作系统下面的应用软件也有.ini文件,用来配置应用软件以实现 ...
- QT从入门到入土(三)——文件的读写操作
引言 文件的读写是很多应用程序具有的功能,甚至某些应用程序就是围绕着某一种格式文件的处 理而开发的,所以文件读写是应用程序开发的一个基本功能. Qt 提供了两种读写纯文本文件的基本方法: 用 QFi ...
- C# 之三类文件的读写( .XML,.INI 和 .TXT 文件)
笔记之用,关于三类.xml, .ini, .txt 文件的 C# 读写,请多多指教! 1,第一类:.xml 文件的读写 先贴上xml文件,下面对这个文件进行操作: <?xml version=& ...
随机推荐
- How to make workflow chart using several tools in Linux?
Just as what I said, I usually use yED to make workflow chart and markdown as the language to write ...
- web register/validation/login system flowchart
I spent several days on building a system about this. And make it work well with serveral thousand l ...
- SESSION会话技术
以下对session会话技术详解: 要了解点http协议理解更佳--->http请求头和http相应头 在session_start的时候,浏览器会向服务器发出请求 在请求的同时,如果是第一次a ...
- Windows平台下的node.js安装
Windows平台下的node.js安装 直接去nodejs的官网http://nodejs.org/上下载nodejs安装程序,双击安装就可以了 测试安装是否成功: 在命令行输入 node –v 应 ...
- [翻译]Webpack解惑
本文译自Webpack - The Confusing Parts,原文需FQ. Webpack现在是React应用程序标配的模块打包器,我估计Angular2和其他框架的用户也在大规模使用.我第一次 ...
- 转]python 结巴分词(jieba)学习
原文 http://www.gowhich.com/blog/147 主题 中文分词Python 源码下载的地址:https://github.com/fxsjy/jieba 演示地址:http:/ ...
- USACO 4.1 Beef McNuggets
Beef McNuggetsHubert Chen Farmer Brown's cows are up in arms, having heard that McDonalds is conside ...
- python绝技 — 侦听802.11 Probe请求
代码 #!/usr/bin/python #--*--coding=utf-8--*-- from scapy.all import * interface = 'wlan1' probeReqs = ...
- 自定义底部导航栏(tabBar)
前言如果大家用过微信提供的tabBar就会发现,他的tabBar有很大的局限性.暂且不说样式局限性了,他提供的app.json配置文件中没有function.这也就意味着使用它提供的这个组件,你只能用 ...
- (三)Harbor使用OpenLDAP认证登陆
接上一篇<安装Harbor>,安装好之后,接下来我们使用OpenLDAP来进行Harbor web界面的登陆验证及权限分配! OpenLDAP: 使用OpenLDAP的都知道,这是一个集 ...