QtTextCodec: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
Written By : Girish Ramakrishnan, ForwardBias Technologies
[[Category:QtInternals]]


=Introduction=
[toc align_right="yes" depth="1"]


In Qt, a QTextCodec provides the capability to translate to/from a particular encoding. New codecs are created by subclassing QTextCodec. Merely instantiating the subclass, registers it with Qt’s codec system. Custom codecs can also be made available as codec plugins.
Written By : Girish Ramakrishnan, ForwardBias Technologies


For an introduction to encoding, see [http://developer.qt.nokia.com/wiki/BasicsOfStringEncoding Basics of Encoding] ''[developer.qt.nokia.com]'' and [http://developer.qt.nokia.com/wiki/BasicsOfLocales Basics of Locales] ''[developer.qt.nokia.com]''.
= Introduction =


=Built-in codecs=
In Qt, a QTextCodec provides the capability to translate to/from a particular encoding. New codecs are created by subclassing QTextCodec. Merely instantiating the subclass, registers it with Qt's codec system. Custom codecs can also be made available as codec plugins.


Various common codecs are implemented in Qt itself using internal QTextCodec subclasses. See [http://doc.qt.nokia.com/4.6/qtextcodec.html Documentation] ''[doc.qt.nokia.com]'' for the built-in codecs. These built-in codecs are instantiated on startup and get registered with the Qt’s codec system.
For an introduction to encoding, see "Basics of Encoding":http://developer.qt.nokia.com/wiki/BasicsOfStringEncoding and "Basics of Locales":http://developer.qt.nokia.com/wiki/BasicsOfLocales.


=Local 8-bit codec=
= Built-in codecs =


The local 8-bit codec can convert from unicode to the character set specified in the locale and vice versa. This codec is called the “System” codec. This codec can be obtained using QTextCodec::codecForLocale() or QTextCodec::codecForName(“System”).
Various common codecs are implemented in Qt itself using internal QTextCodec subclasses. See "Documentation":http://doc.qt.nokia.com/4.6/qtextcodec.html for the built-in codecs. These built-in codecs are instantiated on startup and get registered with the Qt's codec system.


On Windows, the “System” QTextCodec uses MultiByteToWideChar and WideCharToMultiByte (with CP_ACP – <span class="caps">ANSI</span> code page) to convert to and from unicode.
= Local 8-bit codec =


On Unix, coversion is done using ''iconv''. However, Qt can be compiled without iconv support, in which case Qt inspects the <span class="caps">LANG</span>, LC_CTYPE, LC_ALL environment variables to determine the codec. The codec detected has to be a part of the Qt built-in codec list (Otherwise, it defaults to latin-1).
The local 8-bit codec can convert from unicode to the character set specified in the locale and vice versa. This codec is called the &quot;System&amp;quot; codec. This codec can be obtained using QTextCodec::codecForLocale() or QTextCodec::codecForName(&quot;System&amp;quot;).


===Categories:===
On Windows, the &quot;System&amp;quot; QTextCodec uses MultiByteToWideChar and WideCharToMultiByte (with CP_ACP - ANSI code page) to convert to and from unicode.


* [[:Category:QtInternals|QtInternals]]
On Unix, coversion is done using ''iconv''. However, Qt can be compiled without iconv support, in which case Qt inspects the LANG, LC_CTYPE, LC_ALL environment variables to determine the codec. The codec detected has to be a part of the Qt built-in codec list (Otherwise, it defaults to latin-1).

Revision as of 10:18, 24 February 2015


[toc align_right="yes&quot; depth="1&quot;]

Written By : Girish Ramakrishnan, ForwardBias Technologies

Introduction

In Qt, a QTextCodec provides the capability to translate to/from a particular encoding. New codecs are created by subclassing QTextCodec. Merely instantiating the subclass, registers it with Qt's codec system. Custom codecs can also be made available as codec plugins.

For an introduction to encoding, see "Basics of Encoding&quot;:http://developer.qt.nokia.com/wiki/BasicsOfStringEncoding and "Basics of Locales&quot;:http://developer.qt.nokia.com/wiki/BasicsOfLocales.

Built-in codecs

Various common codecs are implemented in Qt itself using internal QTextCodec subclasses. See "Documentation&quot;:http://doc.qt.nokia.com/4.6/qtextcodec.html for the built-in codecs. These built-in codecs are instantiated on startup and get registered with the Qt's codec system.

Local 8-bit codec

The local 8-bit codec can convert from unicode to the character set specified in the locale and vice versa. This codec is called the "System&quot; codec. This codec can be obtained using QTextCodec::codecForLocale() or QTextCodec::codecForName("System&quot;).

On Windows, the "System&quot; QTextCodec uses MultiByteToWideChar and WideCharToMultiByte (with CP_ACP - ANSI code page) to convert to and from unicode.

On Unix, coversion is done using iconv. However, Qt can be compiled without iconv support, in which case Qt inspects the LANG, LC_CTYPE, LC_ALL environment variables to determine the codec. The codec detected has to be a part of the Qt built-in codec list (Otherwise, it defaults to latin-1).