QT妖孽又乱码了,一半好蛋,一半坏蛋
本帖最后由 冥界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;
}
问题能看出出自哪吗? 本帖最后由 冥界3大法王 于 2023-4-18 22:29 编辑
INI文件内容如下:
NoteName=MMMM
editBreakCondition=1
editLogText=2
editLogCondition=3
editCommandText=4
editCommandCondition=5
editSwitchCondition=6
[%E7%BE%8E%E5%A5%B3] //写中文就会这样
NoteName=7
editBreakCondition=8
editLogText=9
editLogCondition=10
editCommandText=11
editCommandCondition=12
editSwitchCondition=13
editBreakCondition=aaa
editLogText=bbb
editLogCondition=ccc
editCommandText=dddd
editCommandCondition=eee
editSwitchCondition=ffff
NoteName=MeiMei
editBreakCondition=Q
editLogText=W
editLogCondition=E
editCommandText=R
editCommandCondition=G
editSwitchCondition=The key value is: {s: EDX} the stack address is: {}
NoteName=H
editBreakCondition=one
editLogText=two
editLogCondition=three
editCommandText=four
editCommandCondition=five
editSwitchCondition=six
NoteName=MM
[美女]
editBreakCondition=one
editLogText=two
editLogCondition=three
editCommandText=four
editCommandCondition=five
editSwitchCondition=six
NoteName=美女
url编码,没乱码 编码问题 如果是中文就是那样的不是乱码 编码看不懂哎 我听说QSettings不支持中文,所以我从来不在ini文件里写中文
如果非要在ini里写中文,可以自己实现一个配置文件操作类
或者改用其他形式的配置文件,比如json,然后用json的操作类来处理 [%E7%BE%8E%E5%A5%B3] //写中文就会这样
这个就是url转码的问题,你先把这个传入url再转成QString,比如这样QUrl(data).toString(); 淡淡灰黑色J 发表于 2023-4-19 09:28
[%E7%BE%8E%E5%A5%B3] //写中文就会这样
这个就是url转码的问题,你先把这个传入url再转成QString,比 ...
问题是读取到控件上,要么没有,要么局部正常,要么写英文的正常,记事本里修改添加的读不出来
页:
[1]
2