I was looking for a way to write to and read from IBM037 encoding in Qt. I was able to achieve that in C# by using
Encoding.GetEncoding("IBM037")
However, I am currently porting an application from C# to C++ using Qt, and I wasn't able to find a way to do so.
Thanks in advance.
Edit: I am aware of QTextCodec but it does not contain a definition for IBM 037. Using it returns a normal text (non-encoded).
You can implement your own class derived from QTextCodec and use tables (like the ones available here ) to perform the translation character by character.
As suggested in the comments, check what stated in the QTextCodec documentation here.
With tables like these you can translate to ASCII 8 bit. Then convert the ASCII characters to Unicode using the functions already provided by the Qt framework.
Related
I'll give a small explanation of my project and my problem:
I have a big C++ project (Old project) which is built on WINAPI with MFC/ATL and DirectX 9 (Windows).
My project is separated to 8 solutions which are 7 Servers and a Client.
The Project uses CString, TCHAR and char*, uses Multi-Byte Character Set.
I would like to add RTL and LTR support for multi language purpose.
My problem:
The source uses CodePage
The source uses CString class for String manipulations.
there is a chat system which add a character at a time to CString class
there are functions like:
void func(TCHAR* str)
{ int x = strlen(str); }
if I type in Hebrew inside client (I set CodePage to 1255), Client render the text as Hebrew, but the string itself shows as
My questions:
How can I get rid of the codepage so I can use multi languages freely?
I was able to fix RTL by playing with Offset, but when there is a mix of RTL and LTR in the same string I have a problem, how can I fix that ?
How can I fix the string watch in the debugger to display text as the right language?
Things worth mentioning:
I am aware that it's a difficult and huge task to do.
I know there is a lib for that called ICU, but I don't know if it's even possible to implement and use with the current situation, if you can explain to me how to implement it, I would be appreciate it.
Thank you for helping me!
I was able to fix RTL by playing with Offset, but when there is a mix of RTL and LTR in the same string I have a problem, how can I fix that ?
The RTL setting is applied to the entire control, as far as I know.
One way to mix those is to render HTML, as in here: https://www.w3.org/International/questions/qa-html-dir.
RichEdit control?
I am going to write software in Qt. Its string literals should be written in native (non-English) language and they should support internationalization. The Qt docs advice to use tr() function for this http://doc.qt.io/qt-5/i18n-source-translation.html
So I try to write:
edit->setText(tr("Фильтр"));
and and I can see only question marks in running app
I replace it with QString::fromStdWString
edit->setText(QString::fromStdWString(L"Фильтр"));
and I can see correct text in my language
So the question is: How should I write non-ASCII strings to be able to correctly display them and translate using Qt Linguist
PS: I use UTF8 encoding for all source files, compiler is vs2013
PS2: I have found QTextCodec::setCodecForTr() function.. but It was removed from Qt 5.4
I think that the best option is to use some kind of Latin1 transliteration inside program source. Then, it's possible to implement both Russian and English versions as normal Qt translations.
BTW. It's possible, with some additional work, to use even plain numbers as translation-placeholders. Just like MFC did.
I found the strange solution for my problem:
By default VS saves files in UTF8 with BOM. In File -> Advanced save options I choose to save file in UTF without BOM and everything works like a charm:
edit->setText(tr("Фильтр"));
It looks like a VS compiler bug.. Interestingly MS claims that its compiler support Unicode only for UTF8 with BOM https://msdn.microsoft.com/en-us/library/xwy0e8f2.aspx
PS: length of "Фильтр" is 12 bytes, so it is really utf8 string
Is there any provision in WinAPI or otherwise for using ini files (or similar style config files) without having to use LPCWSTRs for most things?
My app is using single width ASCII strings throughout, and I've just got round to reading the ini file. Unicode strings are proving to be difficult to deal with and convert between.
If I can't find something fairly simple I think I will just use fstream and be done with it.
.INI files are very old stuff. They were existing decades before the Unicode was introduced. They are simple ASCII files. Tons of applications (including mine) are working with them using simple ASCII Api like GetPrivateProfileString.
If your application uses Unicode default, you can write explicitly GetPrivateProfileStringA. This will force all its params to be simple strings.
Is there a way to show the following as Arabic text?
I used in my project frequently char *sql and ANSI, what can I do ?
Basically a char is just not applicable since it only has 256 possibilities for values. In your code you can use wchar_t instead of char.
I would use Qt and their Internationalization functionality. It supports Unicode and would thus solve your problem. Here's an example showing how to use it for different languages as well. There's also ICU (International Components for Unicode) - look at this.
You may want to read this article by Joel Spolsky on Unicode and character sets to understand what you are facing.
Then find out what kind of internationalization support your GUI toolkit offers.
I am working on a translation application in which users are allowed to give English input and I need to convert to a target language and display on a text box. I am facing problems in displaying unicode characters.
Complex characters are not rendering correctly. I know windows uses Uniscribe for rendering complex characters. So do I need to use that explicitly to get the correct rendering? What is the equivalent of Uniscribe in LINUX and MAC?
I am using C++ with wxWidgets framework and trying to display unicode characters on a text box. Any help would be great!
Considering that Uniscribe support in wxWidgets was merely a Google Summer of code idea this year, it seems unlikely that it's working today.
There's no trivial Linux or Mac equivalent for Uniscribe
Read up on Pango. It's the library that supports full OpenType rendering on Linux. Mac's another story.