读写配置文件
Qt提供了一个读取配置文件的类QSetting
写配置文件
1 2 3 4 5 6
| void write_setting() { QSettings setting("SHAO","My App"); setting.setValue("name","SHAO"); setting.setValue("code",200030); }
|
读配置文件
1 2 3 4 5 6
| void read_setting() { QSettings setting("SHAO","My App"); QString name = setting.value("name").toString(); qint32 code = setting.value("code").toInt(); }
|
读取配置ini文件
配置文件(.ini)格式:
1 2 3 4 5 6
| number=2 [config] node1=sucess size=20 [source] name=PC
|
读取上面的ini文件的简单代码如下所示
1 2 3 4 5 6 7 8 9
| QSettings settings("test.ini",QSettings::IniFormat);
ui->label->setText(settings.value("config/node1").toString());
ui->lineEdit->setText(settings.value("config/size").toString());
int a=settings.value("number").toInt();
qDebug("the value a is: %d",a);
|
处无为之事,行不言之教;作而弗始,生而弗有,为而弗恃,功成不居!
微信支付
支付宝