[Interest] It is possible to get the actual name of a local character set?

Thiago Macieira thiago.macieira at intel.com
Wed Dec 26 15:27:51 CET 2012


On quarta-feira, 26 de dezembro de 2012 16.23.30, Nikos Chantziaras wrote:
> On 26/12/12 16:16, Thiago Macieira wrote:
> > On quarta-feira, 26 de dezembro de 2012 15.54.25, Nikos Chantziaras wrote:
> >> I need the actual name of the character set from which
> >> 
> >> QFile::decodeName() is converting. [...]  Unfortunately, this:
> >>     QTextCodec::codecForLocale()->name()
> >> 
> >> returns "System" on platforms that come with a Qt that uses ICU (pretty
> >> much all Linux distributions.) [...]
> >> 
> >> Is there anything I can do?
> > 
> > There is no Qt API to return that value. You can use the Windows API,
> > POSIX
> > API or ICU API to find out by yourself.
> 
> Too bad.
> 
> Though the API *is* there.  It's QTextCodec::name() and
> QTextCodec::aliases().  IMO it's a mistake by Qt to return "System"
> there, since "System" has exactly zero use.  Or at least
> QTextCodec::aliases() should contain the actual name in one of its elements.

It's not a mistake. It returns "System" meaning "I've just asked Windows or 
ICU (or in Qt 4, iconv) to do it for me and I don't care what the encoding 
was".

Due to construction, in the case of ICU, the QIcuCodec class actually knows 
the name of the system codec, since it needed to ask for it via 
ucnv_getStandardName.

But in the case of the Windows and iconv codecs, we simply don't know. We ask 
the system API to do it (MultiByteToWideChar, WideCharToMultiByte; iconv's 
iconv_open with a NULL source or destination).

Why do you need the codec name anyway?
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121226/57792657/attachment.sig>


More information about the Interest mailing list