qDebug() 在 Windows 上不支持 unicode 字符串 [英] qDebug() doesn't support unicode strings on Windows

查看:30
本文介绍了qDebug() 在 Windows 上不支持 unicode 字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含带有 Unicode 字符的文件名的行编辑,它在 GUI 中正确显示,但是当我使用 qDebug() 打印它时,它将 Unicode 符号显示为问号.

I have a line edit that contains a file name with Unicode-characters and it displays correctly in the GUI, but when I print it with qDebug(), it shows the Unicode symbols as question marks.

例如,对于 "C:/Test/абв",此代码将仅显示 "C:/Test/???".

For example, for "C:/Test/абв" this code will show only "C:/Test/???".

这一行:

qDebug() << ui->lineEditFileName->text();

将显示:

此问题仅在 Windows(XP 和 7)上发生,在 Linux 上运行正常.Qt的版本是4.8.0.

This problem happens only on Windows (both XP and 7), on Linux it works fine. The version of Qt is 4.8.0.

推荐答案

好像 Unicode 文本是'lost in translation',因为 Qt Creator 在阅读时使用了 QString::fromLocal8Bit()调试进程的输出.

It seems that the Unicode text is 'lost in translation', because Qt Creator uses QString::fromLocal8Bit() when reading the debug output from the process.

我从这个帖子中找到了答案:

我不知道 qDebug 用什么把字符串放到控制台上windows(我假设 QString::toLocal8Bit).我知道 Qt Creator 使用QString::fromLocal8Bit(...) 从进程中读取文本.那到处都很好用……但不幸的是,那里只有一个操作系统仍然坚持使用完全破坏任何代码页尝试在一种类型中显示多种脚本.

I don’t know what qDebug uses to put strings onto the console on windows (I assume QString::toLocal8Bit). I know that Qt Creator uses QString::fromLocal8Bit(…) to read the text from the process. That works great everywhere… but unfortunately there is one OS out there that still insists on using codepages that completely break any attempt to display more than one kind of script at a type.

这篇关于qDebug() 在 Windows 上不支持 unicode 字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆