Qt不支持Visual Studio的Unicode或Font错误 [英] Qt dont support Unicode for Visual studio or Font error

查看:93
本文介绍了Qt不支持Visual Studio的Unicode或Font错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,现在我正在学习Qt并与Visual Studio,Extended Qt VS Tool 2.4.3一起使用,我使用的是越南语文字,当我构建程序时,它的文字不错,但按钮显示特殊字符.

im beginer, and now im learning Qt and work with Visual Studio, Extension Qt VS Tool 2.4.3, I use Text is Vietnamese language and when i build program its good but button show special characters.

我已经阅读了一些有关字体错误的主题,但与该错误无关.

I have read a few topic about font errors but its not related with this error.

我的代码:

#include <QtWidgets/QApplication>
#include <QPushButton>
#include <QLabel>

int main(int argc, char *argv[])
{
        QApplication app(argc, argv);
        QPushButton nutBam; // instance 
        nutBam.setText("Nút khẩn cấp !"); //set Text button
        nutBam.show();
        return app.exec();
}

推荐答案

两个问题:

  1. 在源文件中具有硬编码的unicode字符通常不是一个好主意.编辑器和编译器有时可以做正确的事.编辑者可以另存为UTF-8或Unicode.通常,编译器可以假定已读取BOM表头并切换编码.但是团队成员和源代码存储库系统经常做错事.其他人带来了不同的编辑器,源代码控制系统等,并且unicode的内容被弄乱了.它还破坏了差异工具.我已经看到它发生了太多次了.

  1. It's usually not a good idea to have hardcoded unicode characters in a source file. Editors and compilers can sometimes do the right thing. Editors can save as UTF-8 or Unicode. Compilers can assume read BOM headers and switch encoding... usually. But team members and source code repository systems often do the wrong thing. Someone else comes along with a different editor, source control system, etc... and the unicode stuff gets messed up. It also breaks diffing tools as well. I've seen it happen way too many times.

Qt的QString看到您正在将8位ascii字符串传递到QString构造函数中.然后他们的编码解释规则就会生效.因此,使用unicode字符串会更好.

Qt's QString sees you are passing an 8-bit ascii string into the QString constructor. Then their encoding interpretation rules kick in. So it will do better with a unicode string.

要获得两全其美的效果,请将字符串与Unicode转义符一起存储在源代码中,但应将它作为宽字符串传递给QString构造函数:

To get the best of both worlds, store your string in source code with unicode escape characters, but pass to QString constructor as a wide string:

我使用此工具在线将您的某些字符转换为 \ uABCD转义序列.

I used this tool online to convert some of your characters to \uABCD escape sequences.

代替此:

nutBam.setText("Nút khẩn cấp !");

此:

const wchar_t* text = L"N\u00fat kh\u1ea9n c\u1ea5p !";
QString qText(text);
nutBam.setText(qText);

尽管这不再是问题,但请确保您的编辑器将源保存为ANSI或UTF-8,而不是16位unicode.

Although it's no longer an issue, make sure your editor is saving the source as ANSI or UTF-8 and not 16-bit unicode.

目前我还没有在本地安装Qt,但是以上内容可能会合并为:

I don't have Qt installed locally at the moment, but the above might consolidate down to just this:

nutBam.setText(L"N\u00fat kh\u1ea9n c\u1ea5p !");

这篇关于Qt不支持Visual Studio的Unicode或Font错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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