[Interest] Why there is no QChar::toLocal8Bit()?

Tomasz Siekierda sierdzio at gmail.com
Mon Apr 11 11:14:31 CEST 2016


On 11 April 2016 at 10:41, Prav <pr12og2 at programist.ru> wrote:
>>>> So never assume that toLocal8Bit will always give you a single-byte or
>>>> multi-byte string. It varies not only per OS, but also per user.
>>> But is this codec always NOT a 16-bit codec and NOT a 32-bit codec?
> and you answered
>>Why not?
>
> For me "why not" mean that everything is possible. So it could be 16- or 32-bit.
> Probably I did not get your's "why not?" ... because now you are saying it can NOT be 16- or 32-bit!
>
> Well ... сan you clarify your answer please?

Prav, I think you misunderstand what 8bit and codec means here.

toLocal8Bit() will convert the string into 8-bit long chunks (so, a
QByteArray). That's it.

However, your locale can be in UTF-8, in which some characters are 8
bit long, some are 16 bit long, and some are even 32 bit long. If your
text contains a 32bit character, and you use toLocal8bit(), that
single character will occupy 4 places (indexes) in the QByteArray. It
will not be "compressed" into 8 bits, because that is not possible.

At least that's how I understand it now ;-)



More information about the Interest mailing list