[Qt-interest] QByteArray can't not show japanese language chars?
ri at eeda.denso.co.jp
ri at eeda.denso.co.jp
Wed Feb 18 03:53:22 CET 2009
I don't know whether I convert the QByteArray to QString in the right way,here's what I tried:
QByteArray
QString myString = QString( myList.at(xxx) );
and in the QTextStream out
out << myString;
it didn't work either. The japanese characters are transformed to meaningless chars.
But finally I solve this problem using QTextCodec and QTextDecoder as below:
QTextCodec *codec = QTextCodec::codecForName("Shift-JIS");
QTextDecoder *decoder = codec->makeDecoder();
QString string;
while (new_data_available()) {
QByteArray chunk = get_new_data();
string += decoder->toUnicode(chunk);
}
this works fine for me.
Any way, Thank you for your hint!
Shinjiro Mizuki.
-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Thiago Macieira
Sent: Tuesday, February 17, 2009 7:09 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] QByteArray can't not show japanese language chars?
Em Terça-feira 17 Fevereiro 2009, às 09:03:00, ri at eeda.denso.co.jp escreveu:
> hi
>
> I build a QByteArray list like this:
> >> QList<QByteArray> myList;
> >> myList.append( QFile->readLine() )
>
> there're some japanese language characters contained in some lines.
>
> I read all the lines in the file, do my job with myList, and want to
> save it back to the file.
>
> QTextStream out(&file);
> out << myList.at(xxx) << "\n";
>
> but found that all the japanese language characters are transformed to "?"
>
> How do I solve this problem?
QByteArray is, like the name says, an array of bytes. It doesn't specify encoding, so it's technically just binary data.
If you want the concept of characters (Japanese or otherwise), you need to convert it to QString first. In that case, QTextStream will do the right thing when outputting.
--
Thiago Macieira - thiago.macieira (AT) nokia.com
Senior Product Manager - Nokia, Qt Software
Sandakerveien 116, NO-0402 Oslo, Norway
More information about the Qt-interest-old
mailing list