Qt 配置文件读写

在这里用了两个按钮触发配置文件读写操作当pushButton_read按下时读取配置文件内容

pushbutton_write时分别对三个配置文件关键字写入新内容。  

settings.setValue("mainFun",25);

settings.setValue("subFun",40);

settings.setValue("service",1);

 

配置文件格式如下:

[DevOption]
mainFun=50
subFun=40
service=1

 

 

 1 void tcp_client::WriteSettings()
 2 {
 3     QSettings settings("Option.ini", QSettings::IniFormat); // 当前目录的INI文件
 4     settings.beginGroup("DevOption");
 5     settings.setValue("mainFun", 25);
 6     settings.setValue("subFun", 40);
 7     settings.setValue("service", 1);
 8     settings.endGroup();
 9 }
10 
11 void tcp_client::ReadSettings()
12 {
13     QSettings settings("Option.ini", QSettings::IniFormat);
14 
15     int mainFun = settings.value("DevOption/mainFun").toInt();
16     int subFun = settings.value("DevOption/subFun").toInt();
17     QString service = settings.value("DevOption/service").toString();
18 
19     qDebug() << "service" << service;
20     qDebug() << "mainFun" << mainFun;
21     qDebug() << "subFun" << subFun;
22 }
23 
24 
25 void tcp_client::on_pushButton_read_clicked()
26 {
27     ReadSettings();
28 }
29 
30 void tcp_client::on_pushButton_write_clicked()
31 {
32     WriteSettings();
33 }

 

 

 

posted @ 2012-11-07 16:54  24K.纯帅  阅读(1368)  评论(0编辑  收藏  举报