QT中编程实现如下几个功能:
本帖最后由 冥界3大法王 于 2023-4-18 05:45 编辑有以下INI文件:
[美女]
NoteName=MeiMei
editBreakCondition=a
editLogText=b
editLogCondition=c
editCommandText=d
editCommandCondition=e
editSwitchCondition=f
editBreakCondition=aaa
editLogText=bbb
editLogCondition=ccc
editCommandText=dddd
editCommandCondition=eee
editSwitchCondition=ffff
NoteName=MeiMei
[*]按行读取+使用正则(因为我现在要把各自的小节名(美女 、MeiMei。。。)依次添加到ComboBox上(使用正则也行Replace[]替换掉也行!)
[*]支持中文等字符的读取(我下面的代码有问题哟~~ 倘若是中文则没有动静啊)
[*]当改变ComboBox选择时,设置各部分Edit上面的内容
以下是部分代码的实现:
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 新问题来也{:301_974:}
国际惯例配个图,好看些。 本来各自小节名是: 1 2 3 4 5 。。。。这样的读取还算OK
不过显得好弱智啊 。。。一点不专业。。。也不算更好用 本帖最后由 fengdaokanhai 于 2023-4-17 23:51 编辑
可以直接用输入框,设置标记,和几个框关联,标记改变就更新配置;
或者用listview就可以,然后设置值改变事件 使用comboBox的model,你可以看看qt的model/view,这个框架在界面开发中经常用到 QT我真不会呀{:1_907:}
不过中文配置文件改成unicode 试试{:1_907:}
页:
[1]