Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.
QtTextCodec: Difference between revisions
No edit summary |
(clean-up) |
||
(6 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:QtInternals]] | [[Category:QtInternals]] | ||
Written By : Girish Ramakrishnan, ForwardBias Technologies | Written By : Girish Ramakrishnan, ForwardBias Technologies | ||
Line 9: | Line 6: | ||
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. | 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 | For an introduction to encoding, see [[BasicsOfStringEncoding | Basics of Encoding]] and [[BasicsOfLocales | Basics of Locales]]. | ||
= Built-in codecs = | = Built-in codecs = | ||
Various common codecs are implemented in Qt itself using internal QTextCodec subclasses. See | Various common codecs are implemented in Qt itself using internal QTextCodec subclasses. See [http://doc.qt.io/qt-5/qtextcodec.html Documentation] 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 = | = 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 | 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"). | ||
On Windows, the | On Windows, the "System" 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). | 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). |
Latest revision as of 13:06, 24 March 2016
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 and Basics of Locales.
Built-in codecs
Various common codecs are implemented in Qt itself using internal QTextCodec subclasses. See Documentation 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" codec. This codec can be obtained using QTextCodec::codecForLocale() or QTextCodec::codecForName("System").
On Windows, the "System" 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).