本帖最后由 冥界3大法王 于 2023-4-18 05:45 编辑
有以下INI文件:
[美女]
NoteName=MeiMei
editBreakCondition=a
editLogText=b
editLogCondition=c
editCommandText=d
editCommandCondition=e
editSwitchCondition=f
[MeiMei]
editBreakCondition=aaa
editLogText=bbb
editLogCondition=ccc
editCommandText=dddd
editCommandCondition=eee
editSwitchCondition=ffff
NoteName=MeiMei
- 按行读取+使用正则(因为我现在要把各自的小节名(美女 、MeiMei。。。)依次添加到ComboBox上(使用正则也行Replace[]替换掉也行!)
- 支持中文等字符的读取(我下面的代码有问题哟~~ 倘若是中文则没有动静啊)
- 当改变ComboBox选择时,设置各部分Edit上面的内容
以下是部分代码的实现:
[C++] 纯文本查看 复制代码 void SimpleTraceDialog::on_ReadINI_clicked()
{
QString strPath = QCoreApplication::applicationDirPath();
QDir dir(strPath);
bool bSuccess = dir.cdUp();
if (bSuccess == true) {
strPath = dir.path() + "/";
}
QSettings *configIniRead = new QSettings(strPath + "config.ini", QSettings::IniFormat);
configIniRead->setIniCodec("UTF-8");
QString XiaoJieName = configIniRead->value("/" + ui->XiaoJieName->text() + "/NoteName").toString();
ui->XiaoJieName->setText(XiaoJieName);
QString editBreakCondition1 = configIniRead->value("/" + ui->XiaoJieName->text() + "/editBreakCondition").toString();
//configIniRead->setIniCodec("UTF-8");
ui->editBreakCondition->setText(editBreakCondition1);
QString editLogText1 = configIniRead->value("/" + ui->XiaoJieName->text() + "/editLogText").toString();
//configIniRead->setIniCodec("UTF-8");
ui->editLogText->setText(editLogText1);
QString editLogCondition1 = configIniRead->value("/" + ui->XiaoJieName->text() + "/editLogCondition").toString();
ui->editLogCondition->setText(editLogCondition1);
QString editCommandText1 = configIniRead->value("/" + ui->XiaoJieName->text() + "/editCommandText").toString();
//configIniRead->setIniCodec("UTF-8");
ui->editCommandText->setText(editCommandText1);
QString editCommandCondition1 = configIniRead->value("/" + ui->XiaoJieName->text() + "/editCommandCondition").toString();
//configIniRead->setIniCodec("UTF-8");
ui->editCommandCondition->setText(editCommandCondition1);
QString editSwitchCondition1 = configIniRead->value("/" + ui->XiaoJieName->text() + "/editSwitchCondition").toString();
//configIniRead->setIniCodec("UTF-8");
ui->editSwitchCondition->setText(editSwitchCondition1);
delete configIniRead;
}
@evea 新问题来也
国际惯例配个图,好看些。 |