首页 > 代码库 > 【Qt 】QSettings写ini配置文件
【Qt 】QSettings写ini配置文件
QSettings写ini配置文件(Qt版本5.2):
#include "inidemo.h"#include <QSettings>#include <QTextCodec>IniDemo::IniDemo(QWidget *parent) : QMainWindow(parent){ ui.setupUi(this); QSettings settings("setting.ini",QSettings::IniFormat); settings.clear(); settings.beginGroup("MAIN FILE INFO"); settings.setValue("exeTitle", "1111122"); settings.setValue("curDir", QApplication::applicationDirPath()); settings.endGroup(); for (int i = 0; i < 5; ++i) { settings.beginGroup(tr("Torrents%1").arg(i)); settings.setValue("sourceFileName", i); settings.setValue("destinationFolder",i); settings.setValue("uploadedBytes", i); settings.setValue("downloadedBytes", i); settings.setValue("resumeState", i); settings.endGroup(); } settings.sync();}IniDemo::~IniDemo(){}
生成的配置文件如下, so easy:
[MAIN%20FILE%20INFO]exeTitle=1111122curDir=D:/CPP_Pro/QT_prjs/IniDemo/Win32/Debug[Torrents0]sourceFileName=0destinationFolder=0uploadedBytes=0downloadedBytes=0resumeState=0[Torrents1]sourceFileName=1destinationFolder=1uploadedBytes=1downloadedBytes=1resumeState=1[Torrents2]sourceFileName=2destinationFolder=2uploadedBytes=2downloadedBytes=2resumeState=2[Torrents3]sourceFileName=3destinationFolder=3uploadedBytes=3downloadedBytes=3resumeState=3[Torrents4]sourceFileName=4destinationFolder=4uploadedBytes=4downloadedBytes=4resumeState=4
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。