PDA

View Full Version : Make QTextStream write with UTF8 enabled?



hakermania
27th December 2010, 23:17
This is the code:


QFile file(home16);
if (!file.open(QIODevice::WriteOnly)) {
cerr << "Cannot open file" << home16 << " for writing. The reason: "
<< qPrintable(file.errorString()) << endl;
cout << "Try again."; system("echo "" > /home/$USER/.config/WallpaperChanger/Checks/text_to_buton");
}
QTextStream out(&file);
out << realpath;
file.close();

where `home16` is a file's path and `realpath` is a char* which contains greek characters, How will i write this character to the file `home16` without the greek characters to turn to "chinese"? Thx in advance!

nroberts
27th December 2010, 23:37
How will i write this character to the file `home16` without the greek characters to turn to "chinese"? Thx in advance!

I don't think I understand this question. You say you've got "greek characters" in this char* sequence and want to turn them into "chinese characters"? What kind of translation are you expecting this to be?

Do you know what code-set you're trying to translate from and to? AFAIK the codes for greek and chinese characters aren't in the same area when using Unicode (UTF8).

hakermania
27th December 2010, 23:48
No, my friend, my question is clear. i want the greek characters (the char* realpath) to be written to the file `home16` WITHOUT to turn into "chinese" (I mean weird symbols etc):confused:

nroberts
27th December 2010, 23:53
No, my friend, my question is clear. i want the greek characters (the char* realpath) to be written to the file `home16` WITHOUT to turn into "chinese" (I mean weird symbols etc):confused:

Well, if it was clear I wouldn't be explaining what I didn't understand...but oh well.

Have you tried converting your byte sequence into a QString using the appropriate ::from XXX function? For instance, if your byte sequence is in UTF-8 then my guess would be that you'd get better results with:


out << QString::fromUTF8(realpath);


Also, not all programs are going to display your text output correctly. You'll need something specifically able to deal with Unicode and have the right font loaded, etc... It is possible that you've already gotten correct output but are looking at it with something not smart enough to read it correctly.

hakermania
28th December 2010, 00:05
Thank you, this worked :)
And a note: LINUX are not as WINDOWS, they have programs that CAN read Unicode Characters HAHAHA :cool:

nroberts
28th December 2010, 00:33
Thank you, this worked :)
And a note: LINUX are not as WINDOWS, they have programs that CAN read Unicode Characters HAHAHA :cool:

That actually used to be fairly difficult to get working correctly. Glad to see that it's improved.

hakermania
28th December 2010, 08:57
If you are talking about a GUI program that could read unicode, you're right, but as long as I use Linux, nano and vim read unicode perfectly.