问题描述
我有一个包含带有 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(...) 从进程中读取文本.那到处都很好用……但不幸的是,那里只有一个操作系统仍然坚持使用完全破坏任何代码页尝试在一种类型中显示多种脚本.
这篇关于qDebug() 在 Windows 上不支持 unicode 字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!