Qt读写INI配置文件

void WriteSettings()
{
    //QSettings settings("Software Inc", "Spreadsheet"); // windows在注册表中建立建 Software Inc -> Spreadsheet
    QSettings settings("Option.ini", QSettings::IniFormat); // 当前目录的INI文件
    settings.beginGroup("DevOption");
    settings.setValue("mainFun", 25);
    settings.setValue("subFun", 40);
    settings.setValue("service", 1);
    settings.endGroup();
}

void ReadSettings()
{
    QSettings settings("Option.ini", QSettings::IniFormat);

    int mainFun = settings.value("DevOption/mainFun").toInt();
    int subFun = settings.value("DevOption/subFun").toInt();
    QString service = settings.value("DevOption/service").toString();

    qDebug() << "service" << service;
    qDebug() << "mainFun" << mainFun;
    qDebug() << "subFun" << subFun;
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    WriteSettings();
    ReadSettings();
    
    return a.exec();
}

  

posted on 2012-06-14 14:50 chuncn 阅读(...) 评论(...) 编辑 收藏

导航