.ini 文件是Initialization File的缩写,即初始化文件。是windows的系统配置文件所采用的存储格式,INI文件由节、键、值组成。
写操作:
// QString filename = QFileDialog::getSaveFileName(this,"Save");
// QString txt = ui->plainTextEdit->toPlainText();
// QFile file(filename);
// if(!file.open(QIODevice::ReadWrite | QIODevice::Text))
// {
// QMessageBox::warning(this,"file write","can't,open",QMessageBox::Yes);
// }
// QTextStream in(&file);
// in << txt << "\n";//TXT文档保存
QSettings setting("Information.ini",QSettings::IniFormat);
setting.setIniCodec(QTextCodec::codecForName("UTF-8"));//设置编码格式
setting.beginGroup("Devinformation");
setting.setValue("userName",ui->userlineEdit->text());
setting.setValue("Name",ui->namelineEdit->text());
setting.setValue("Sex",ui->sexboBox->currentText());
setting.setValue("Depart",ui->buMentextEdit->toPlainText());
setting.setValue("Age",ui->agelineEdit->text());
setting.setValue("Other",ui->beiZhulineEdit->text());
setting.setValue("Abstract",ui->plainTextEdit->toPlainText());
setting.endGroup();//ini保存文档
读操作:
QSettings setting("Information.ini",QSettings::IniFormat);
setting.setIniCodec(QTextCodec::codecForName("UTF-8"));
QString username = setting.value("Devinformation/userName").toString();
QString name = setting.value("Devinformation/Name").toString();
QString sex = setting.value("Devinformation/Sex").toString();
QString bumen = setting.value("Devinformation/Depart").toString();
QString age = setting.value("Devinformation/Age").toString();
QString beizhu = setting.value("Devinformation/Other").toString();
QString shuoming = setting.value("Devinformation/Abstract").toString();
qDebug() << username;
qDebug() << name;
qDebug() << sex;
qDebug() << bumen;
qDebug() << age;
qDebug() << beizhu;
qDebug() << shuoming;