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

Frédéric Marchal frederic.marchal at wowtechnology.com
Mon Apr 11 14:31:02 CEST 2016


On Monday 11 April 2016 12:57:35 Prav wrote:
> Hi, Tomasz.
> 
> > Prav, I think you misunderstand what 8bit and codec means here.
> > ...
> > However, your locale can be in UTF-8, in which some characters are 8 bit
> > long ...
> Agree. I already undestood from previous answers that locale can multibyte.
> Let me rephare my question:
> 
> Can locale be UTF-16 or any other 16- or 32-bit locale?

Windows is UTF-16. It has a 8-bit fall back encoding to which toLocal8bit 
converts the string. I don't know how toLocal8bit degrades on processors where 
a char is 16 or 32-bit long. I guess it makes sense to still output an array 
of "chars" in that case.

On processors with 8-bit char, I certainly don't expect QString::toLocal8bit() 
to output a 16-bit or 32-bit array. That's the job of 
QString::toStdU16String() and QString::toStdU32String() or possibly 
QString::toStdWString().

Think of QString::toLocal8bit() as a mean of converting the internally UTF-16 
encoded QString to whatever can be written to a 8-bit output device on the 
host computer.

If you want to share your string with another computer, use QString::toUtf8().

Prav, you haven't told us your purpose (or I failed to spot it). If you simply 
want a numeric value to identify a single character, can you use 
QChar::unicode()?

Frederic




More information about the Interest mailing list