kevin55

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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=1111122
curDir=D:/CPP_Pro/QT_prjs/IniDemo/Win32/Debug

[Torrents0]
sourceFileName=0
destinationFolder=0
uploadedBytes=0
downloadedBytes=0
resumeState=0

[Torrents1]
sourceFileName=1
destinationFolder=1
uploadedBytes=1
downloadedBytes=1
resumeState=1

[Torrents2]
sourceFileName=2
destinationFolder=2
uploadedBytes=2
downloadedBytes=2
resumeState=2

[Torrents3]
sourceFileName=3
destinationFolder=3
uploadedBytes=3
downloadedBytes=3
resumeState=3

[Torrents4]
sourceFileName=4
destinationFolder=4
uploadedBytes=4
downloadedBytes=4
resumeState=4

 

posted on 2014-08-19 00:50  kernel_main  阅读(2513)  评论(0编辑  收藏  举报