Amharic alphabet is not recognized by Qt Creator and compiled application on Windows
-
Hi Qt Community,
I've been developing an application with Amharic content using Qt 5.15.2. On Ubuntu Linux and Android the amharic characters are recognised and displayed. However on Windows string literals in the source code are displayed by empty spaces in both Qt creator and running application. What could be the cause, I have tried QString::fromUtf8 and QTextCodec::setCodecForLocale with UTF-8? Is the compiler missing a flag?
-
Hi @Felly, and welcome!
Ensure that your source code is saved in UTF-8 encoding, and try using Unicode string literals (
u8"..."
): -
The default file encoding in tools->options->texteditor is UTF-8 with BOM. In addition, if I open the source code in Notepad the Amharic characters are visible but evidently not on Qt Creator. @VRonin I agree with you, I hard coded the string literal with u8"ኢትዮጵያና" to try figure out the cause for the problem and hence was added for this reason. Unfortunately it is still empty space on a qtextedit or on breakpoint during debugging the QString is " ". Interestingly I ran the application in Linux with wine and I can see the Amharic so I suspect this may very well be a Windows issue that is evading me considering I can see Amharic on other applications.
-
As my colleagues already told you - don't use any non-ascii chars. The MSVC compiler is simply stupid and due to the history of windows to not use utf-8 by default all depends somehow on the current codepage set - so it may work with one setting but when you then run it with another codepage all gets screwed up. You can try to tell them that it's an utf-8 encoded source by passing /utf-8 to your compile options.
-
So it turns out that the default Windows font cannot display Amharic characters. You need to switch to a font that can (like Nyala [1])
All 4 labels below display fine for me on Qt 5.14.1 + MinGW 7.3.0:
QApplication app(argc, argv); app.setFont(QFont("Nyala")); QLabel l1(u8"ኢትዮጵያና"); QLabel l2(u8"\u12a2\u1275\u12ee\u1335\u12eb\u1293"); QLabel l3( QString::fromUtf8(u8"ኢትዮጵያና") ); QLabel l4( QString::fromUtf8(u8"\u12a2\u1275\u12ee\u1335\u12eb\u1293") );
@Felly said in Amharic alphabet is not recognized by Qt Creator and compiled application on Windows:
on Windows string literals in the source code are displayed by empty spaces in both Qt creator
You can set Qt Creator's font in Tools > Options... > Text Editor > Font & Colors
[1] https://community.adobe.com/t5/type-typography/amharic-ethiopian-anybody/m-p/1116653#M854