PDA

View Full Version : Polish chars in the HTML generated by Qt.



Alan_K
20th March 2011, 13:41
Hi. Look at my code. I have a very big problem, namely the encoding of the HTML file. So, polish chars in QMessageBox works correctly, but in text of the "out" no so good.


QTextCodec::setCodecForCStrings(QTextCodec::codecF orName("UTF-8"));
QTextCodec::setCodecForLocale(QTextCodec::codecFor Name("UTF-8"));
QTextCodec::setCodecForTr(QTextCodec::codecForName ("UTF-8"));

Example:

out << "<h2>INFORMACJA O GOTOWOŚCI DZIECKA<br />DO PODJĘCIA NAUKI W SZKOLE PODSTAWOWEJ</h2>\n";
looks:

INFORMACJA O GOTOWOÂŒCI DZIECKA
DO PODJÊCIA NAUKI W SZKOLE PODSTAWOWEJ

Ê =/= Ę :(

I coded the files in UTF-8 with BOM. Polish characters, which are get from the checboxe's label works correctly.

wysota
20th March 2011, 14:35
AFAIK QTextStream uses its own codec. Have a look at QTextStream::setCodec().

Alan_K
20th March 2011, 15:12
You can clearly? I have already tried to use this feature, but I do not know how to change the encoding on correct. UTF-8, Windows-1250 not working and all other attempt wail.

wysota
20th March 2011, 16:34
What is the encoding of your source code file?

Alan_K
20th March 2011, 16:50
What is the encoding of your source code file?

"System" :o

wysota
20th March 2011, 16:52
I'm not asking what QtCreator shows, I'm asking what the encoding is. There is no encoding called "System". Since you're using Windows it's probably UTF-8. See if wrapping your strings in QString::fromUtf8() helps.

Alan_K
20th March 2011, 17:05
I'm not asking what QtCreator shows, I'm asking what the encoding is. There is no encoding called "System". Since you're using Windows it's probably UTF-8. See if wrapping your strings in QString::fromUtf8() helps.

Not working, but QString::fromAscii() works correctly. Thanks.

wysota
20th March 2011, 17:13
Well, it shouldn't. Use fromUtf8() and remove your calls that set explicit codecs for C strings.

Rhayader
20th March 2011, 17:46
Since you're using Windows it's probably UTF-8. See if wrapping your strings in QString::fromUtf8() helps.

I know for sure that in greek Windows Xp the system default is always Windows-1253. Can't tell for sure about polish but in a similar case the QString::fromLocal8bit is more suitable, Of course there is the option to change your sources encodings to UTF-8

wysota
20th March 2011, 18:23
fromLocal8Bit() won't be any good because local encodings change and the source file encoding stays the same. So using local8Bit() will fail if the file gets compiled on say... Linux with Chinese locale but fromUtf8() will work because the file is still encoded in utf-8 regardless of the settings of the computer (and its OS) it is opened on.

Lesiok
21st March 2011, 09:29
Maybe this is a compiler problem ?
We have all sources coded in 1250 and this works perfectly :

QTextCodec::setCodecForTr(QTextCodec::codecForName ("Windows-1250"));
QTextCodec::setCodecForCStrings(QTextCodec::codecF orName("Windows-1250"));