简体   繁体   English

Qt 5编码问题

[英]Qt 5 encoding problems

I had an application built using Qt 4. It used latin-1 as source and I always used QString::fromLatin1. 我有一个使用Qt 4构建的应用程序。它使用latin-1作为源,并且我始终使用QString :: fromLatin1。 However, when trying to port to Qt 5 (Actually, I both used Qt 5 and Windows 8 together, but I don't think it's windows' fault) the encoding actually appears kinda right, with some weird space before/after the text. 但是,当尝试移植到Qt 5时(实际上,我同时使用了Qt 5和Windows 8,但我不认为这是Windows的错),编码实际上看起来是正确的,在文本之前/之后有一些奇怪的空格。

This is the app running with Qt 5 / Windows 8: 这是在Qt 5 / Windows 8上运行的应用程序:

截图

As you can see, the ç and and ã do appear correct, with some weird space added between them. 如您所见, çã确实显示正确,并且在它们之间添加了一些奇怪的空间。 Also, the ó character appears correct with no space. 另外, ó字符显示正确,没有空格。

This is how I set the QLabel: 这就是我设置QLabel的方式:

m_msgWelcome->setText(QString("Bem vindo ao biocódigo!\nSelecione uma opção ao lado para iniciar"));

I already tried both QString::fromUtf8 and QString::fromLatin1 with no success. 我已经尝试了QString::fromUtf8QString::fromLatin1没有成功。

With Qt5, normally, you can just saving all your files in UTF-8 (no need to use method like QString::fromAnythingEncoding ). 通常,使用Qt5,您可以将所有文件保存为UTF-8(无需使用QString::fromAnythingEncoding类的方法)。

With Qt Creator you can do this by : Edit then Select Encoding (for all your files). 使用Qt Creator,您可以通过以下方法执行此操作: 编辑然后选择编码 (针对所有文件)。

For the future, you can also change the default setting : Tools > Options > Text Editor > Behavior > Default encoding then put UTF-8 . 为了将来,您还可以更改默认设置: 工具 > 选项 > 文本编辑器 > 行为 > 默认编码,然后输入UTF-8

If the spacing problem is still there try using a different font. 如果间距问题仍然存在,请尝试使用其他字体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM