简体   繁体   中英

Qt 5 encoding problems

I had an application built using Qt 4. It used latin-1 as source and I always used 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.

This is the app running with 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:

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.

With Qt5, normally, you can just saving all your files in UTF-8 (no need to use method like QString::fromAnythingEncoding ).

With Qt Creator you can do this by : Edit then Select Encoding (for all your files).

For the future, you can also change the default setting : Tools > Options > Text Editor > Behavior > Default encoding then put UTF-8 .

If the spacing problem is still there try using a different font.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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