好友
阅读权限 40
听众
最后登录 1970-1-1
本帖最后由 冥界3大法王 于 2023-4-18 21:59 编辑
QT妖孽又乱码了,一半好蛋,一半坏蛋 另一个问题,我自己写出的INI文件中,英文一半正常(手工改写的读取不出来)写入的那部分英文读取OK 中文一部分是乱码
废话说完,上代码:
#include "SimpleTraceDialog.h"
#include "ui_SimpleTraceDialog.h"
#include "Bridge.h"
#include <QMessageBox>
#include "BrowseDialog.h"
#include "MiscUtil.h"
#include <QSettings>
#pragma execution_character_set("utf-8");
#include <QDir>
#include <QRegularExpression>
#include <QFile>
void SimpleTraceDialog::on_WriteINI_clicked()
{
QString strPath = QCoreApplication::applicationDirPath();
QDir dir(strPath);
bool bSuccess = dir.cdUp();
if (bSuccess == true) {
strPath = dir.path() + "/";
}
QSettings *configIniWrite = new QSettings(strPath + "config.ini", QSettings::IniFormat);
configIniWrite->setIniCodec("UTF-8");
configIniWrite->setValue("/" + ui->XiaoJieName->text() + "/editBreakCondition", ui->editBreakCondition->text());
configIniWrite->setValue("/" + ui->XiaoJieName->text() + "/editLogText", ui->editLogText->text());
configIniWrite->setValue("/" + ui->XiaoJieName->text() + "/editLogCondition", ui->editLogCondition->text());
configIniWrite->setValue("/" + ui->XiaoJieName->text() + "/editCommandText", ui->editCommandText->text());
configIniWrite->setValue("/" + ui->XiaoJieName->text() + "/editCommandCondition", ui->editCommandCondition->text());
configIniWrite->setValue("/" + ui->XiaoJieName->text() + "/editSwitchCondition", ui->editSwitchCondition->text());
configIniWrite->setValue("/" + ui->XiaoJieName->text() + "/NoteName", ui->XiaoJieName->text());
delete configIniWrite;
}
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();
ui->editBreakCondition->setText(editBreakCondition1);
QString editLogText1 = configIniRead->value("/" + ui->XiaoJieName->text() + "/editLogText").toString();
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();
ui->editCommandText->setText(editCommandText1);
QString editCommandCondition1 = configIniRead->value("/" + ui->XiaoJieName->text() + "/editCommandCondition").toString();
ui->editCommandCondition->setText(editCommandCondition1);
QString editSwitchCondition1 = configIniRead->value("/" + ui->XiaoJieName->text() + "/editSwitchCondition").toString();
ui->editSwitchCondition->setText(editSwitchCondition1);
delete configIniRead;
}
问题能看出出自哪吗?
发帖前要善用【论坛搜索 】 功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。