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

被折叠的 条评论
为什么被折叠?



