吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1178|回复: 11
收起左侧

[求助] QT妖孽又乱码了,一半好蛋,一半坏蛋

[复制链接]
冥界3大法王 发表于 2023-4-18 21:58
本帖最后由 冥界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:00
本帖最后由 冥界3大法王 于 2023-4-18 22:29 编辑

INI文件内容如下:
[1]
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

[MeiMei]
editBreakCondition=aaa
editLogText=bbb
editLogCondition=ccc
editCommandText=dddd
editCommandCondition=eee
editSwitchCondition=ffff
NoteName=MeiMei

[registry]
editBreakCondition=Q
editLogText=W
editLogCondition=E
editCommandText=R
editCommandCondition=G
editSwitchCondition=The key value is: {s: EDX}   the stack address is: {[ESP]}
NoteName=H

[MM]
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=美女

熊猫拍板砖 发表于 2023-4-18 23:03
fengdaokanhai 发表于 2023-4-19 01:08
236A 发表于 2023-4-19 03:20
如果是中文就是那样的不是乱码
15935517293 发表于 2023-4-19 07:47
编码看不懂哎
头像被屏蔽
xy20200214 发表于 2023-4-19 08:09
提示: 该帖被管理员或版主屏蔽
codeaftercode 发表于 2023-4-19 08:52
我听说QSettings不支持中文,所以我从来不在ini文件里写中文
如果非要在ini里写中文,可以自己实现一个配置文件操作类
或者改用其他形式的配置文件,比如json,然后用json的操作类来处理
淡淡灰黑色J 发表于 2023-4-19 09:28
[%E7%BE%8E%E5%A5%B3]    //写中文就会这样
这个就是url转码的问题,你先把这个传入url再转成QString,比如这样QUrl(data).toString();

免费评分

参与人数 1吾爱币 +2 热心值 +1 收起 理由
冥界3大法王 + 2 + 1 谢谢@Thanks!

查看全部评分

 楼主| 冥界3大法王 发表于 2023-4-19 13:09
淡淡灰黑色J 发表于 2023-4-19 09:28
[%E7%BE%8E%E5%A5%B3]    //写中文就会这样
这个就是url转码的问题,你先把这个传入url再转成QString,比 ...

问题是读取到控件上,要么没有,要么局部正常,要么写英文的正常,记事本里修改添加的读不出来
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 00:21

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表