[Qt-interest] why .fromLocal8Bit() is needed

Andreas Pakulat apaku at gmx.de
Fri Mar 20 09:04:35 CET 2009


On 20.03.09 12:52:47, chandrasekar wagmare wrote:
> hi friends,
>         i try all the assistant documents but cant find ... what is the
> difference between this two .. to get readyReadStandardError() from
> QProcess()
>           1.
>               QString path = process.readAllStandardError();
>               path = outputtextedit->setText(path);
> 
>           2.
>                QByteArray newData = process.readAllStandardError();
>              QString text = outputTextEdit->toPlainText()
>                                       + QString::fromLocal8Bit(newData);
>                     outputTextEdit->setPlainText(text);
> 
> why we need to convert QString as like 2 nd one .... what will happen if i
> use 1 st condition

You'll get broken text if the process sends anything but plain ascii. See
the QString methods that take a QByteArray as input, they all use
QString::fromAscii internally (or if you're lucky fromLatin1 which would
work for some non-ascii characters).

Even fromLocal8Bit might be wrong, if your external process always outputs
in some specific 8 bit encoding (for example it could always print out in
utf8) or some other encoding. Basically you need to find out how your
external process prints out its text, wether you maybe can force it to use
some specific encoding.

Andreas

-- 
You will be awarded the Nobel Peace Prize... posthumously.



More information about the Qt-interest-old mailing list