前言:项目中会用到.ini文件存储保存数据
一、写.ini文件
QString path = "D:/lns/model.ini";
QSettings* m_IniFile = new QSettings(path,QSettings::IniFormat);
m_IniFile -> beginGroup("alarm");
m_IniFile -> setValue("0",QString::number(examopen.worksheet));
m_IniFile -> setValue("1",QString::number(examopen.SN_number));
m_IniFile -> endGroup();
delete m_IniFile;
二、读.ini文件
QString path = "D:/lns/model.ini";
QSettings *demo = new QSettings(path, QSettings::IniFormat);
demo -> beginGroup("alarm");
QStringList str = demo -> allKeys();
QString key1 = str.at(0);
QString value1 = demo -> value(key1).toString();
examopen.worksheet = value1.toInt();
QString key2 = str.at(1);
QString value2 = demo -> value(key2).toString();
examopen.SN_number = value2.toInt();
demo -> endGroup();