qt 中文 遇到 问题 记录

本文探讨了在Qt中使用不同方式对QString进行编码转换时遇到的问题,并给出了相应的解决办法。通过对比toUtf8(), toLocal8Bit(), toStdString()等方法,帮助理解不同编码间的区别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码如下:

    QString profilePath = "在目录";
    fprintf(stderr, "profilePath: %s\n", profilePath.toUtf8());


    fprintf(stderr, "profilePath: %s\n", profilePath.toLocal8Bit().constData());


    fprintf(stderr, "profilePath: %s\n", qPrintable(profilePath));

    fprintf(stdout, "33 %s\n", profilePath.toStdString().c_str());
    fflush(stdout);
    fprintf(stderr, "55 %s\n", profilePath.toUtf8().data());

    fprintf(stderr, "77 %s\n", profilePath.toLatin1().data());

    QByteArray localMsg = profilePath.toLocal8Bit();

    fprintf(stderr, "99 %s\n", localMsg.constData());

如果把

QString profilePath = "在目录"; 

修改为

QString profilePath = "你好"; 

就没有那个问题,具体原因不明

解决方法,请参考
https://blog.youkuaiyun.com/wowocpp/article/details/120483528

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值