PDA

View Full Version : Problems with text encoding



LMZ
3rd July 2007, 11:42
Hi guys! I have a problem with the text encoding.
I get a string with regexp:


QRegExp rxTitle("...");
. . . . . . . . . . . . . .
qstrTitle = rxTitle.cap(2);

This text contains some local characters (ru), and it's not displayed normally.
I tried to use QString::fromLocal8Bit:


. . . . . . . . . . . . . . . .
qstrTitle = QString::fromLocal8Bit( qstrTitle.toAscii() );

No result.. I tried to use QString::toUtf8().. the same result..

How can I display normally that text?

wysota
3rd July 2007, 12:15
Display where?

jacek
3rd July 2007, 12:22
If every string literal uses the same encoding, you can set it using QTextCodec::setCodecForCStrings() and QTextCodec::setCodecForTr(). If there's only one such string, make sure it's encoded in UTF-8 and use QString::fromUtf8() or use appropriate QTextCodec to convert it to QString.

LMZ
3rd July 2007, 12:39
2wysota: no matter.. I need to create a file with, wich name must be that string. (I try to display it on a message box)

2jacek: thx, I'll try it..

LMZ
3rd July 2007, 12:49
2jacek: thank you so much! QString::fromUtf8() solved my problem. now it works perfectly!