C++:Qt 5.3无法显示UTF-8字符

bwe*_*ber 4 c++ unicode qt utf-8

我试图在Visual Studio 2013中使用Qt和C++在按钮上显示一个unicode字符(欧元符号).我尝试了以下代码:

_rotateLeftButton->setText("\u20AC");
Run Code Online (Sandbox Code Playgroud)

_rotateLeftButton->setText("€");
Run Code Online (Sandbox Code Playgroud)

_rotateLeftButton->setText(QString::fromUtf8("\u20AC"));
Run Code Online (Sandbox Code Playgroud)

_rotateLeftButton->setText(QString::fromUtf8("€"));
Run Code Online (Sandbox Code Playgroud)

但是,所有这些行都会导致以下结果:

字符无法显示

除了moc文件(.cxx)之外,我的所有代码文件都是UTF-8编码的.无论出于何种原因,moc可执行文件都不使用unicode生成它们.然而,我无法正确显示此unicode符号.我还尝试设置另一种字体,而不是默认的字体,但没有成功.有谁知道可能是什么问题?

谢谢您的帮助.

bob*_*nce 8

QString::fromUtf8("€")
Run Code Online (Sandbox Code Playgroud)

如果文件真的被处理为UTF-8,将会工作.正如@nm评论的那样,VS需要一些人造物理清单的帮助才能确保这一点.

QString::fromUtf8("\u20AC")
Run Code Online (Sandbox Code Playgroud)

\u在字节字符串文字中没有意义.您可以使用\x字节转义为UTF-8编码版本拼写它:

QString::fromUtf8("\xE2\x82\xAC")
Run Code Online (Sandbox Code Playgroud)

或者使用宽字符串文字:

QString::fromWCharArray(L"\u20AC")
Run Code Online (Sandbox Code Playgroud)