Reputation: 11
I am experiencing very strange behavior with cyrillic letters. I'm using Qt 5.12.6, Windows 10 (64 bit).
The whole application wrote with QML, as you can see some words don't make any sense they are not Russian. All QML Text elements behave the wrong way.
The top login buttons underlied red look like this
import QtQuick 2.7
import QtQuick.Controls 2.0
Button {
id: loginPageButton
font.capitalization: Font.AllUppercase
checkable: true
flat: true
contentItem: Text {
text: loginPageButton.text
font: loginPageButton.font
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
}
using
LoginPageButton {
id: newAccountButton
text: qsTr("CREATE AN ACCOUNT")
font.pixelSize: 16
ButtonGroup.group: btnGroup
checked: false
Layout.alignment: Qt.AlignCenter | Qt.AlignVCenter
}
retranslate is made in such way
QGuiApplication::removeTranslator(&m_currentTranslator);
bool isLoaded = m_currentTranslator.load(QString("tr_%1").arg(locale), QCoreApplication::applicationDirPath() + "/translations/");
if (isLoaded)
QGuiApplication::installTranslator(&m_currentTranslator);
m_engine.retranslate(); // QQmlApplicationEngine
and i have to say that the bug is reproduced only on some machines not all...
Upvotes: 0
Views: 811
Reputation: 11
The problem was in the Roboto font - we changed it to the different one and everything went to normal.
Upvotes: 0
Reputation: 1349
A "Ḱ" indicates Macedonian language. So your string encoding is wrong, if you want Russian.
Quoting from the Qt docs: "The application may occasionally require encodings other than the default local 8-bit encoding. For example, an application in a Cyrillic KOI8-R locale (the de-facto standard locale in Russia) might need to output Cyrillic in the ISO 8859-5 encoding. Code for this would be:
QString string = ...; // some Unicode text
QTextCodec *codec = QTextCodec::codecForName("ISO 8859-5");
QByteArray encodedString = codec->fromUnicode(string);
For converting Unicode to local 8-bit encodings, a shortcut is available: the QString::toLocal8Bit() function returns such 8-bit data. Another useful shortcut is QString::toUtf8(), which returns text in the 8-bit UTF-8 encoding: this perfectly preserves Unicode information while looking like plain ASCII if the text is wholly ASCII.
For converting the other way, there are the QString::fromUtf8() and QString::fromLocal8Bit() convenience functions, or the general code, demonstrated by this conversion from ISO 8859-5 Cyrillic to Unicode conversion:
QByteArray encodedString = ...; // some ISO 8859-5 encoded text
QTextCodec *codec = QTextCodec::codecForName("ISO 8859-5");
QString string = codec->toUnicode(encodedString);
" (1)
Upvotes: 1