qtextcodec.html 40.4 KB
Newer Older
xuebingbing's avatar
xuebingbing committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qtextcodec.cpp -->
  <title>QTextCodec Class | Qt Core 5.11</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.11</a></td><td ><a href="qtcore-index.html">Qt Core</a></td><td ><a href="qtcore-module.html">C++ Classes</a></td><td >QTextCodec</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.11.2 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-types">Public Types</a></li>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#static-public-members">Static Public Members</a></li>
<li class="level1"><a href="#protected-functions">Protected Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
<li class="level2"><a href="#creating-your-own-codec-class">Creating Your Own Codec Class</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QTextCodec Class</h1>
<!-- $$$QTextCodec-brief -->
<p>The <a href="qtextcodec.html">QTextCodec</a> class provides conversions between text encodings. <a href="#details">More...</a></p>
<!-- @@@QTextCodec -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QTextCodec&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += core</td></tr></table></div><ul>
<li><a href="qtextcodec-members.html">List of all members, including inherited members</a></li>
<li><a href="qtextcodec-obsolete.html">Obsolete members</a></li>
</ul>
<p><b>Note:</b> All functions in this class are <a href="../qtdoc/threads-reentrancy.html">reentrant</a>.</p>
<ul>
<li><a href="qtextcodec.html#setCodecForLocale">setCodecForLocale</a>(QTextCodec *c)</li>
<li><a href="qtextcodec.html#dtor.QTextCodec">~QTextCodec</a>()</li>
</ul>
<p><b>Note:</b> These functions are also <a href="../qtdoc/threads-reentrancy.html">thread-safe</a>:</p>
<ul>
<li><a href="qtextcodec.html#codecForName">codecForName</a>(const QByteArray &amp;name)</li>
<li><a href="qtextcodec.html#codecForMib">codecForMib</a>(int mib)</li>
<li><a href="qtextcodec.html#availableCodecs">availableCodecs</a>()</li>
<li><a href="qtextcodec.html#availableMibs">availableMibs</a>()</li>
<li><a href="qtextcodec.html#codecForLocale">codecForLocale</a>()</li>
</ul>
<a name="public-types"></a>
<h2 id="public-types">Public Types</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> class </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec-converterstate.html">ConverterState</a></b></td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#ConversionFlag-enum">ConversionFlag</a></b> { DefaultConversion, ConvertInvalidToNull, IgnoreHeader }</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> flags </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#ConversionFlag-enum">ConversionFlags</a></b></td></tr>
</table></div>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual QList&lt;QByteArray&gt; </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#aliases">aliases</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#canEncode">canEncode</a></b>(QChar <i>ch</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#canEncode-1">canEncode</a></b>(const QString &amp;<i>s</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#canEncode-2">canEncode</a></b>(QStringView <i>s</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QByteArray </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#fromUnicode">fromUnicode</a></b>(const QString &amp;<i>str</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QByteArray </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#fromUnicode-1">fromUnicode</a></b>(QStringView <i>str</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QByteArray </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#fromUnicode-2">fromUnicode</a></b>(const QChar *<i>input</i>, int <i>number</i>, QTextCodec::ConverterState *<i>state</i> = nullptr) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QTextDecoder *</td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#makeDecoder">makeDecoder</a></b>(QTextCodec::ConversionFlags <i>flags</i> = DefaultConversion) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QTextEncoder *</td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#makeEncoder">makeEncoder</a></b>(QTextCodec::ConversionFlags <i>flags</i> = DefaultConversion) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual int </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#mibEnum">mibEnum</a></b>() const = 0</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QByteArray </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#name">name</a></b>() const = 0</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#toUnicode">toUnicode</a></b>(const QByteArray &amp;<i>a</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#toUnicode-1">toUnicode</a></b>(const char *<i>chars</i>) const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QString </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#toUnicode-2">toUnicode</a></b>(const char *<i>input</i>, int <i>size</i>, QTextCodec::ConverterState *<i>state</i> = nullptr) const</td></tr>
</table></div>
<a name="static-public-members"></a>
<h2 id="static-public-members">Static Public Members</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> QList&lt;QByteArray&gt; </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#availableCodecs">availableCodecs</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QList&lt;int&gt; </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#availableMibs">availableMibs</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QTextCodec *</td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#codecForHtml">codecForHtml</a></b>(const QByteArray &amp;<i>ba</i>, QTextCodec *<i>defaultCodec</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QTextCodec *</td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#codecForHtml-1">codecForHtml</a></b>(const QByteArray &amp;<i>ba</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QTextCodec *</td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#codecForLocale">codecForLocale</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QTextCodec *</td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#codecForMib">codecForMib</a></b>(int <i>mib</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QTextCodec *</td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#codecForName">codecForName</a></b>(const QByteArray &amp;<i>name</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QTextCodec *</td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#codecForName-1">codecForName</a></b>(const char *<i>name</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QTextCodec *</td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#codecForUtfText">codecForUtfText</a></b>(const QByteArray &amp;<i>ba</i>, QTextCodec *<i>defaultCodec</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QTextCodec *</td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#codecForUtfText-1">codecForUtfText</a></b>(const QByteArray &amp;<i>ba</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#setCodecForLocale">setCodecForLocale</a></b>(QTextCodec *<i>c</i>)</td></tr>
</table></div>
<a name="protected-functions"></a>
<h2 id="protected-functions">Protected Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#QTextCodec">QTextCodec</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#dtor.QTextCodec">~QTextCodec</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QByteArray </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#convertFromUnicode">convertFromUnicode</a></b>(const QChar *<i>input</i>, int <i>number</i>, QTextCodec::ConverterState *<i>state</i>) const = 0</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual QString </td><td class="memItemRight bottomAlign"><b><a href="qtextcodec.html#convertToUnicode">convertToUnicode</a></b>(const char *<i>chars</i>, int <i>len</i>, QTextCodec::ConverterState *<i>state</i>) const = 0</td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QTextCodec-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The <a href="qtextcodec.html">QTextCodec</a> class provides conversions between text encodings.</p>
<p>Qt uses Unicode to store, draw and manipulate strings. In many situations you may wish to deal with data that uses a different encoding. For example, most Japanese documents are still stored in Shift-JIS or ISO 2022-JP, while Russian users often have their documents in KOI8-R or Windows-1251.</p>
<p>Qt provides a set of <a href="qtextcodec.html">QTextCodec</a> classes to help with converting non-Unicode formats to and from Unicode. You can also create your own codec classes.</p>
<p>The supported encodings are:</p>
<ul>
<li><a href="codec-big5.html">Big5</a></li>
<li><a href="codec-big5hkscs.html">Big5-HKSCS</a></li>
<li>CP949</li>
<li><a href="codec-eucjp.html">EUC-JP</a></li>
<li><a href="codec-euckr.html">EUC-KR</a></li>
<li><a href="codec-gbk.html">GB18030</a></li>
<li>HP-ROMAN8</li>
<li>IBM 850</li>
<li>IBM 866</li>
<li>IBM 874</li>
<li><a href="codecs-jis.html">ISO 2022-JP</a></li>
<li>ISO 8859-1 to 10</li>
<li>ISO 8859-13 to 16</li>
<li>Iscii-Bng, Dev, Gjr, Knd, Mlm, Ori, Pnj, Tlg, and Tml</li>
<li>KOI8-R</li>
<li>KOI8-U</li>
<li>Macintosh</li>
<li><a href="codec-sjis.html">Shift-JIS</a></li>
<li>TIS-620</li>
<li><a href="codec-tscii.html">TSCII</a></li>
<li>UTF-8</li>
<li>UTF-16</li>
<li>UTF-16BE</li>
<li>UTF-16LE</li>
<li>UTF-32</li>
<li>UTF-32BE</li>
<li>UTF-32LE</li>
<li>Windows-1250 to 1258</li>
</ul>
<p>If Qt is compiled with ICU support enabled, most codecs supported by ICU will also be available to the application.</p>
<p><a href="qtextcodec.html">QTextCodec</a>s can be used as follows to convert some locally encoded string to Unicode. Suppose you have some string encoded in Russian KOI8-R encoding, and want to convert it to Unicode. The simple way to do it is like this:</p>
<pre class="cpp">

  <span class="type"><a href="qbytearray.html">QByteArray</a></span> encodedString <span class="operator">=</span> <span class="string">&quot;...&quot;</span>;
  <span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span> <span class="operator">*</span>codec <span class="operator">=</span> <span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span><span class="operator">::</span>codecForName(<span class="string">&quot;KOI8-R&quot;</span>);
  <span class="type"><a href="qstring.html">QString</a></span> string <span class="operator">=</span> codec<span class="operator">-</span><span class="operator">&gt;</span>toUnicode(encodedString);

</pre>
<p>After this, <code>string</code> holds the text converted to Unicode. Converting a string from Unicode to the local encoding is just as easy:</p>
<pre class="cpp">

  <span class="type"><a href="qstring.html">QString</a></span> string <span class="operator">=</span> <span class="string">&quot;...&quot;</span>;
  <span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span> <span class="operator">*</span>codec <span class="operator">=</span> <span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span><span class="operator">::</span>codecForName(<span class="string">&quot;KOI8-R&quot;</span>);
  <span class="type"><a href="qbytearray.html">QByteArray</a></span> encodedString <span class="operator">=</span> codec<span class="operator">-</span><span class="operator">&gt;</span>fromUnicode(string);

</pre>
<p>To read or write files in various encodings, use <a href="qtextstream.html">QTextStream</a> and its <a href="qtextstream.html#setCodec">setCodec()</a> function. See the <a href="../qtwidgets/qtwidgets-tools-codecs-example.html">Codecs</a> example for an application of <a href="qtextcodec.html">QTextCodec</a> to file I/O.</p>
<p>Some care must be taken when trying to convert the data in chunks, for example, when receiving it over a network. In such cases it is possible that a multi-byte character will be split over two chunks. At best this might result in the loss of a character and at worst cause the entire conversion to fail.</p>
<p>The approach to use in these situations is to create a <a href="qtextdecoder.html">QTextDecoder</a> object for the codec and use this <a href="qtextdecoder.html">QTextDecoder</a> for the whole decoding process, as shown below:</p>
<pre class="cpp">

  <span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span> <span class="operator">*</span>codec <span class="operator">=</span> <span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span><span class="operator">::</span>codecForName(<span class="string">&quot;Shift-JIS&quot;</span>);
  <span class="type"><a href="qtextdecoder.html">QTextDecoder</a></span> <span class="operator">*</span>decoder <span class="operator">=</span> codec<span class="operator">-</span><span class="operator">&gt;</span>makeDecoder();

  <span class="type"><a href="qstring.html">QString</a></span> string;
  <span class="keyword">while</span> (new_data_available()) {
      <span class="type"><a href="qbytearray.html">QByteArray</a></span> chunk <span class="operator">=</span> get_new_data();
      string <span class="operator">+</span><span class="operator">=</span> decoder<span class="operator">-</span><span class="operator">&gt;</span>toUnicode(chunk);
  }
  <span class="keyword">delete</span> decoder;

</pre>
<p>The <a href="qtextdecoder.html">QTextDecoder</a> object maintains state between chunks and therefore works correctly even if a multi-byte character is split between chunks.</p>
<a name="creating-your-own-codec-class"></a>
<h3 >Creating Your Own Codec Class</h3>
<p>Support for new text encodings can be added to Qt by creating <a href="qtextcodec.html">QTextCodec</a> subclasses.</p>
<p>The pure virtual functions describe the encoder to the system and the coder is used as required in the different text file formats supported by <a href="qtextstream.html">QTextStream</a>, and under X11, for the locale-specific character input and output.</p>
<p>To add support for another encoding to Qt, make a subclass of <a href="qtextcodec.html">QTextCodec</a> and implement the functions listed in the table below.</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Function</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td ><a href="qtextcodec.html#name">name</a>()</td><td >Returns the official name for the encoding. If the encoding is listed in the <a href="http://www.iana.org/assignments/character-sets/character-sets.xml">IANA character-sets encoding file</a>, the name should be the preferred MIME name for the encoding.</td></tr>
<tr valign="top" class="even"><td ><a href="qtextcodec.html#aliases">aliases</a>()</td><td >Returns a list of alternative names for the encoding. <a href="qtextcodec.html">QTextCodec</a> provides a default implementation that returns an empty list. For example, &quot;ISO-8859-1&quot; has &quot;latin1&quot;, &quot;CP819&quot;, &quot;IBM819&quot;, and &quot;iso-ir-100&quot; as aliases.</td></tr>
<tr valign="top" class="odd"><td ><a href="qtextcodec.html#mibEnum">mibEnum()</a></td><td >Return the MIB enum for the encoding if it is listed in the <a href="http://www.iana.org/assignments/character-sets/character-sets.xml">IANA character-sets encoding file</a>.</td></tr>
<tr valign="top" class="even"><td ><a href="qtextcodec.html#convertToUnicode">convertToUnicode</a>()</td><td >Converts an 8-bit character string to Unicode.</td></tr>
<tr valign="top" class="odd"><td ><a href="qtextcodec.html#convertFromUnicode">convertFromUnicode</a>()</td><td >Converts a Unicode string to an 8-bit character string.</td></tr>
</table></div>
</div>
<p><b>See also </b><a href="qtextstream.html">QTextStream</a>, <a href="qtextdecoder.html">QTextDecoder</a>, <a href="qtextencoder.html">QTextEncoder</a>, and <a href="../qtwidgets/qtwidgets-tools-codecs-example.html">Text Codecs Example</a>.</p>
<!-- @@@QTextCodec -->
<div class="types">
<h2>Member Type Documentation</h2>
<!-- $$$ConversionFlag$$$DefaultConversion$$$ConvertInvalidToNull$$$IgnoreHeader$$$FreeFunction -->
<h3 class="flags" id="ConversionFlag-enum"><a name="ConversionFlag-enum"></a>enum QTextCodec::<span class="name">ConversionFlag</span><br/>flags QTextCodec::<span class="name">ConversionFlags</span></h3>
<div class="table"><table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><code>QTextCodec::DefaultConversion</code></td><td class="topAlign tblval"><code>0</code></td><td class="topAlign">No flag is set.</td></tr>
<tr><td class="topAlign"><code>QTextCodec::ConvertInvalidToNull</code></td><td class="topAlign tblval"><code>0x80000000</code></td><td class="topAlign">If this flag is set, each invalid input character is output as a null character.</td></tr>
<tr><td class="topAlign"><code>QTextCodec::IgnoreHeader</code></td><td class="topAlign tblval"><code>0x1</code></td><td class="topAlign">Ignore any Unicode byte-order mark and don't generate any.</td></tr>
</table></div>
<p>The ConversionFlags type is a typedef for <a href="qflags.html">QFlags</a>&lt;ConversionFlag&gt;. It stores an OR combination of ConversionFlag values.</p>
<!-- @@@ConversionFlag -->
</div>
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QTextCodec[overload1]$$$QTextCodec -->
<h3 class="fn" id="QTextCodec"><a name="QTextCodec"></a><code>[protected] </code>QTextCodec::<span class="name">QTextCodec</span>()</h3>
<p>Constructs a <a href="qtextcodec.html">QTextCodec</a>, and gives it the highest precedence. The <a href="qtextcodec.html">QTextCodec</a> should always be constructed on the heap (i.e&#x2e; with <code>new</code>). Qt takes ownership and will delete it when the application terminates.</p>
<!-- @@@QTextCodec -->
<!-- $$$~QTextCodec[overload1]$$$~QTextCodec -->
<h3 class="fn" id="dtor.QTextCodec"><a name="dtor.QTextCodec"></a><code>[virtual protected] </code>QTextCodec::<span class="name">~QTextCodec</span>()</h3>
<p>Destroys the <a href="qtextcodec.html">QTextCodec</a>. Note that you should not delete codecs yourself: once created they become Qt's responsibility.</p>
<p><b>Warning:</b> This function is not <a href="../qtdoc/threads-reentrancy.html">reentrant</a>.</p>
<!-- @@@~QTextCodec -->
<!-- $$$aliases[overload1]$$$aliases -->
<h3 class="fn" id="aliases"><a name="aliases"></a><code>[virtual] </code><span class="type"><a href="qlist.html">QList</a></span>&lt;<span class="type"><a href="qbytearray.html">QByteArray</a></span>&gt; QTextCodec::<span class="name">aliases</span>() const</h3>
<p>Subclasses can return a number of aliases for the codec in question.</p>
<p>Standard aliases for codecs can be found in the <a href="http://www.iana.org/assignments/character-sets/character-sets.xml">IANA character-sets encoding file</a>.</p>
<!-- @@@aliases -->
<!-- $$$availableCodecs[overload1]$$$availableCodecs -->
<h3 class="fn" id="availableCodecs"><a name="availableCodecs"></a><code>[static] </code><span class="type"><a href="qlist.html">QList</a></span>&lt;<span class="type"><a href="qbytearray.html">QByteArray</a></span>&gt; QTextCodec::<span class="name">availableCodecs</span>()</h3>
<p>Returns the list of all available codecs, by name. Call <a href="qtextcodec.html#codecForName">QTextCodec::codecForName</a>() to obtain the <a href="qtextcodec.html">QTextCodec</a> for the name.</p>
<p>The list may contain many mentions of the same codec if the codec has aliases.</p>
<p><b>Note:</b> This function is <a href="../qtdoc/threads-reentrancy.html">thread-safe</a>.</p>
<p><b>See also </b><a href="qtextcodec.html#availableMibs">availableMibs</a>(), <a href="qtextcodec.html#name">name</a>(), and <a href="qtextcodec.html#aliases">aliases</a>().</p>
<!-- @@@availableCodecs -->
<!-- $$$availableMibs[overload1]$$$availableMibs -->
<h3 class="fn" id="availableMibs"><a name="availableMibs"></a><code>[static] </code><span class="type"><a href="qlist.html">QList</a></span>&lt;<span class="type">int</span>&gt; QTextCodec::<span class="name">availableMibs</span>()</h3>
<p>Returns the list of MIBs for all available codecs. Call <a href="qtextcodec.html#codecForMib">QTextCodec::codecForMib</a>() to obtain the <a href="qtextcodec.html">QTextCodec</a> for the MIB.</p>
<p><b>Note:</b> This function is <a href="../qtdoc/threads-reentrancy.html">thread-safe</a>.</p>
<p><b>See also </b><a href="qtextcodec.html#availableCodecs">availableCodecs</a>() and <a href="qtextcodec.html#mibEnum">mibEnum</a>().</p>
<!-- @@@availableMibs -->
<!-- $$$canEncode[overload1]$$$canEncodeQChar -->
<h3 class="fn" id="canEncode"><a name="canEncode"></a><span class="type">bool</span> QTextCodec::<span class="name">canEncode</span>(<span class="type"><a href="qchar.html">QChar</a></span> <i>ch</i>) const</h3>
<p>Returns <code>true</code> if the Unicode character <i>ch</i> can be fully encoded with this codec; otherwise returns <code>false</code>.</p>
<!-- @@@canEncode -->
<!-- $$$canEncode$$$canEncodeconstQString& -->
<h3 class="fn" id="canEncode-1"><a name="canEncode-1"></a><span class="type">bool</span> QTextCodec::<span class="name">canEncode</span>(const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>s</i>) const</h3>
<p>This is an overloaded function.</p>
<p><i>s</i> contains the string being tested for encode-ability.</p>
<!-- @@@canEncode -->
<!-- $$$canEncode$$$canEncodeQStringView -->
<h3 class="fn" id="canEncode-2"><a name="canEncode-2"></a><span class="type">bool</span> QTextCodec::<span class="name">canEncode</span>(<span class="type"><a href="qstringview.html">QStringView</a></span> <i>s</i>) const</h3>
<p>This is an overloaded function.</p>
<p>Returns <code>true</code> if the Unicode string <i>s</i> can be fully encoded with this codec; otherwise returns <code>false</code>.</p>
<p>This function was introduced in  Qt 5.10.</p>
<!-- @@@canEncode -->
<!-- $$$codecForHtml[overload1]$$$codecForHtmlconstQByteArray&QTextCodec* -->
<h3 class="fn" id="codecForHtml"><a name="codecForHtml"></a><code>[static] </code><span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span> *QTextCodec::<span class="name">codecForHtml</span>(const <span class="type"><a href="qbytearray.html">QByteArray</a></span> &amp;<i>ba</i>, <span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span> *<i>defaultCodec</i>)</h3>
<p>Tries to detect the encoding of the provided snippet of HTML in the given byte array, <i>ba</i>, by checking the BOM (Byte Order Mark) and the content-type meta header and returns a <a href="qtextcodec.html">QTextCodec</a> instance that is capable of decoding the html to unicode. If the codec cannot be detected from the content provided, <i>defaultCodec</i> is returned.</p>
<p>This function was introduced in  Qt 4.4.</p>
<p><b>See also </b><a href="qtextcodec.html#codecForUtfText">codecForUtfText</a>().</p>
<!-- @@@codecForHtml -->
<!-- $$$codecForHtml$$$codecForHtmlconstQByteArray& -->
<h3 class="fn" id="codecForHtml-1"><a name="codecForHtml-1"></a><code>[static] </code><span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span> *QTextCodec::<span class="name">codecForHtml</span>(const <span class="type"><a href="qbytearray.html">QByteArray</a></span> &amp;<i>ba</i>)</h3>
<p>This is an overloaded function.</p>
<p>Tries to detect the encoding of the provided snippet of HTML in the given byte array, <i>ba</i>, by checking the BOM (Byte Order Mark) and the content-type meta header and returns a <a href="qtextcodec.html">QTextCodec</a> instance that is capable of decoding the html to unicode. If the codec cannot be detected, this overload returns a Latin-1 <a href="qtextcodec.html">QTextCodec</a>.</p>
<!-- @@@codecForHtml -->
<!-- $$$codecForLocale[overload1]$$$codecForLocale -->
<h3 class="fn" id="codecForLocale"><a name="codecForLocale"></a><code>[static] </code><span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span> *QTextCodec::<span class="name">codecForLocale</span>()</h3>
<p>Returns a pointer to the codec most suitable for this locale.</p>
<p>On Windows, the codec will be based on a system locale. On Unix systems, the codec will might fall back to using the <i>iconv</i> library if no builtin codec for the locale can be found.</p>
<p>Note that in these cases the codec's name will be &quot;System&quot;.</p>
<p><b>Note:</b> This function is <a href="../qtdoc/threads-reentrancy.html">thread-safe</a>.</p>
<p><b>See also </b><a href="qtextcodec.html#setCodecForLocale">setCodecForLocale</a>().</p>
<!-- @@@codecForLocale -->
<!-- $$$codecForMib[overload1]$$$codecForMibint -->
<h3 class="fn" id="codecForMib"><a name="codecForMib"></a><code>[static] </code><span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span> *QTextCodec::<span class="name">codecForMib</span>(<span class="type">int</span> <i>mib</i>)</h3>
<p>Returns the <a href="qtextcodec.html">QTextCodec</a> which matches the <a href="qtextcodec.html#mibEnum">MIBenum</a> <i>mib</i>.</p>
<p><b>Note:</b> This function is <a href="../qtdoc/threads-reentrancy.html">thread-safe</a>.</p>
<!-- @@@codecForMib -->
<!-- $$$codecForName[overload1]$$$codecForNameconstQByteArray& -->
<h3 class="fn" id="codecForName"><a name="codecForName"></a><code>[static] </code><span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span> *QTextCodec::<span class="name">codecForName</span>(const <span class="type"><a href="qbytearray.html">QByteArray</a></span> &amp;<i>name</i>)</h3>
<p>Searches all installed <a href="qtextcodec.html">QTextCodec</a> objects and returns the one which best matches <i>name</i>; the match is case-insensitive. Returns 0 if no codec matching the name <i>name</i> could be found.</p>
<p><b>Note:</b> This function is <a href="../qtdoc/threads-reentrancy.html">thread-safe</a>.</p>
<!-- @@@codecForName -->
<!-- $$$codecForName$$$codecForNameconstchar* -->
<h3 class="fn" id="codecForName-1"><a name="codecForName-1"></a><code>[static] </code><span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span> *QTextCodec::<span class="name">codecForName</span>(const <span class="type">char</span> *<i>name</i>)</h3>
<p>Searches all installed <a href="qtextcodec.html">QTextCodec</a> objects and returns the one which best matches <i>name</i>; the match is case-insensitive. Returns 0 if no codec matching the name <i>name</i> could be found.</p>
<!-- @@@codecForName -->
<!-- $$$codecForUtfText[overload1]$$$codecForUtfTextconstQByteArray&QTextCodec* -->
<h3 class="fn" id="codecForUtfText"><a name="codecForUtfText"></a><code>[static] </code><span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span> *QTextCodec::<span class="name">codecForUtfText</span>(const <span class="type"><a href="qbytearray.html">QByteArray</a></span> &amp;<i>ba</i>, <span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span> *<i>defaultCodec</i>)</h3>
<p>Tries to detect the encoding of the provided snippet <i>ba</i> by using the BOM (Byte Order Mark) and returns a <a href="qtextcodec.html">QTextCodec</a> instance that is capable of decoding the text to unicode. If the codec cannot be detected from the content provided, <i>defaultCodec</i> is returned.</p>
<p>This function was introduced in  Qt 4.6.</p>
<p><b>See also </b><a href="qtextcodec.html#codecForHtml">codecForHtml</a>().</p>
<!-- @@@codecForUtfText -->
<!-- $$$codecForUtfText$$$codecForUtfTextconstQByteArray& -->
<h3 class="fn" id="codecForUtfText-1"><a name="codecForUtfText-1"></a><code>[static] </code><span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span> *QTextCodec::<span class="name">codecForUtfText</span>(const <span class="type"><a href="qbytearray.html">QByteArray</a></span> &amp;<i>ba</i>)</h3>
<p>This is an overloaded function.</p>
<p>Tries to detect the encoding of the provided snippet <i>ba</i> by using the BOM (Byte Order Mark) and returns a <a href="qtextcodec.html">QTextCodec</a> instance that is capable of decoding the text to unicode. If the codec cannot be detected, this overload returns a Latin-1 <a href="qtextcodec.html">QTextCodec</a>.</p>
<p><b>See also </b><a href="qtextcodec.html#codecForHtml">codecForHtml</a>().</p>
<!-- @@@codecForUtfText -->
<!-- $$$convertFromUnicode[overload1]$$$convertFromUnicodeconstQChar*intQTextCodec::ConverterState* -->
<h3 class="fn" id="convertFromUnicode"><a name="convertFromUnicode"></a><code>[pure virtual protected] </code><span class="type"><a href="qbytearray.html">QByteArray</a></span> QTextCodec::<span class="name">convertFromUnicode</span>(const <span class="type"><a href="qchar.html">QChar</a></span> *<i>input</i>, <span class="type">int</span> <i>number</i>, <span class="type"><a href="qtextcodec-converterstate.html">QTextCodec::ConverterState</a></span> *<i>state</i>) const</h3>
<p><a href="qtextcodec.html">QTextCodec</a> subclasses must reimplement this function.</p>
<p>Converts the first <i>number</i> of characters from the <i>input</i> array from Unicode to the encoding of the subclass, and returns the result in a <a href="qbytearray.html">QByteArray</a>.</p>
<p><i>state</i> can be 0 in which case the conversion is stateless and default conversion rules should be used. If state is not 0, the codec should save the state after the conversion in <i>state</i>, and adjust the <code>remainingChars</code> and <code>invalidChars</code> members of the struct.</p>
<!-- @@@convertFromUnicode -->
<!-- $$$convertToUnicode[overload1]$$$convertToUnicodeconstchar*intQTextCodec::ConverterState* -->
<h3 class="fn" id="convertToUnicode"><a name="convertToUnicode"></a><code>[pure virtual protected] </code><span class="type"><a href="qstring.html">QString</a></span> QTextCodec::<span class="name">convertToUnicode</span>(const <span class="type">char</span> *<i>chars</i>, <span class="type">int</span> <i>len</i>, <span class="type"><a href="qtextcodec-converterstate.html">QTextCodec::ConverterState</a></span> *<i>state</i>) const</h3>
<p><a href="qtextcodec.html">QTextCodec</a> subclasses must reimplement this function.</p>
<p>Converts the first <i>len</i> characters of <i>chars</i> from the encoding of the subclass to Unicode, and returns the result in a <a href="qstring.html">QString</a>.</p>
<p><i>state</i> can be 0, in which case the conversion is stateless and default conversion rules should be used. If state is not 0, the codec should save the state after the conversion in <i>state</i>, and adjust the <code>remainingChars</code> and <code>invalidChars</code> members of the struct.</p>
<!-- @@@convertToUnicode -->
<!-- $$$fromUnicode[overload1]$$$fromUnicodeconstQString& -->
<h3 class="fn" id="fromUnicode"><a name="fromUnicode"></a><span class="type"><a href="qbytearray.html">QByteArray</a></span> QTextCodec::<span class="name">fromUnicode</span>(const <span class="type"><a href="qstring.html">QString</a></span> &amp;<i>str</i>) const</h3>
<p>Converts <i>str</i> from Unicode to the encoding of this codec, and returns the result in a <a href="qbytearray.html">QByteArray</a>.</p>
<!-- @@@fromUnicode -->
<!-- $$$fromUnicode$$$fromUnicodeQStringView -->
<h3 class="fn" id="fromUnicode-1"><a name="fromUnicode-1"></a><span class="type"><a href="qbytearray.html">QByteArray</a></span> QTextCodec::<span class="name">fromUnicode</span>(<span class="type"><a href="qstringview.html">QStringView</a></span> <i>str</i>) const</h3>
<p>This is an overloaded function.</p>
<p>Converts <i>str</i> from Unicode to the encoding of this codec, and returns the result in a <a href="qbytearray.html">QByteArray</a>.</p>
<p>This function was introduced in  Qt 5.10.</p>
<!-- @@@fromUnicode -->
<!-- $$$fromUnicode$$$fromUnicodeconstQChar*intQTextCodec::ConverterState* -->
<h3 class="fn" id="fromUnicode-2"><a name="fromUnicode-2"></a><span class="type"><a href="qbytearray.html">QByteArray</a></span> QTextCodec::<span class="name">fromUnicode</span>(const <span class="type"><a href="qchar.html">QChar</a></span> *<i>input</i>, <span class="type">int</span> <i>number</i>, <span class="type"><a href="qtextcodec-converterstate.html">QTextCodec::ConverterState</a></span> *<i>state</i> = nullptr) const</h3>
<p>Converts the first <i>number</i> of characters from the <i>input</i> array from Unicode to the encoding of this codec, and returns the result in a <a href="qbytearray.html">QByteArray</a>.</p>
<p>The <i>state</i> of the convertor used is updated.</p>
<!-- @@@fromUnicode -->
<!-- $$$makeDecoder[overload1]$$$makeDecoderQTextCodec::ConversionFlags -->
<h3 class="fn" id="makeDecoder"><a name="makeDecoder"></a><span class="type"><a href="qtextdecoder.html">QTextDecoder</a></span> *QTextCodec::<span class="name">makeDecoder</span>(<span class="type"><a href="qtextcodec.html#ConversionFlag-enum">QTextCodec::ConversionFlags</a></span> <i>flags</i> = DefaultConversion) const</h3>
<p>Creates a <a href="qtextdecoder.html">QTextDecoder</a> with a specified <i>flags</i> to decode chunks of <code>char *</code> data to create chunks of Unicode data.</p>
<p>The caller is responsible for deleting the returned object.</p>
<p>This function was introduced in  Qt 4.7.</p>
<!-- @@@makeDecoder -->
<!-- $$$makeEncoder[overload1]$$$makeEncoderQTextCodec::ConversionFlags -->
<h3 class="fn" id="makeEncoder"><a name="makeEncoder"></a><span class="type"><a href="qtextencoder.html">QTextEncoder</a></span> *QTextCodec::<span class="name">makeEncoder</span>(<span class="type"><a href="qtextcodec.html#ConversionFlag-enum">QTextCodec::ConversionFlags</a></span> <i>flags</i> = DefaultConversion) const</h3>
<p>Creates a <a href="qtextencoder.html">QTextEncoder</a> with a specified <i>flags</i> to encode chunks of Unicode data as <code>char *</code> data.</p>
<p>The caller is responsible for deleting the returned object.</p>
<p>This function was introduced in  Qt 4.7.</p>
<!-- @@@makeEncoder -->
<!-- $$$mibEnum[overload1]$$$mibEnum -->
<h3 class="fn" id="mibEnum"><a name="mibEnum"></a><code>[pure virtual] </code><span class="type">int</span> QTextCodec::<span class="name">mibEnum</span>() const</h3>
<p>Subclasses of <a href="qtextcodec.html">QTextCodec</a> must reimplement this function. It returns the MIBenum (see <a href="http://www.iana.org/assignments/character-sets/character-sets.xml">IANA character-sets encoding file</a> for more information). It is important that each <a href="qtextcodec.html">QTextCodec</a> subclass returns the correct unique value for this function.</p>
<!-- @@@mibEnum -->
<!-- $$$name[overload1]$$$name -->
<h3 class="fn" id="name"><a name="name"></a><code>[pure virtual] </code><span class="type"><a href="qbytearray.html">QByteArray</a></span> QTextCodec::<span class="name">name</span>() const</h3>
<p><a href="qtextcodec.html">QTextCodec</a> subclasses must reimplement this function. It returns the name of the encoding supported by the subclass.</p>
<p>If the codec is registered as a character set in the <a href="http://www.iana.org/assignments/character-sets/character-sets.xml">IANA character-sets encoding file</a> this method should return the preferred mime name for the codec if defined, otherwise its name.</p>
<!-- @@@name -->
<!-- $$$setCodecForLocale[overload1]$$$setCodecForLocaleQTextCodec* -->
<h3 class="fn" id="setCodecForLocale"><a name="setCodecForLocale"></a><code>[static] </code><span class="type">void</span> QTextCodec::<span class="name">setCodecForLocale</span>(<span class="type"><a href="qtextcodec.html#QTextCodec">QTextCodec</a></span> *<i>c</i>)</h3>
<p>Set the codec to <i>c</i>; this will be returned by <a href="qtextcodec.html#codecForLocale">codecForLocale</a>(). If <i>c</i> is a null pointer, the codec is reset to the default.</p>
<p>This might be needed for some applications that want to use their own mechanism for setting the locale.</p>
<p><b>Warning:</b> This function is not <a href="../qtdoc/threads-reentrancy.html">reentrant</a>.</p>
<p><b>See also </b><a href="qtextcodec.html#codecForLocale">codecForLocale</a>().</p>
<!-- @@@setCodecForLocale -->
<!-- $$$toUnicode[overload1]$$$toUnicodeconstQByteArray& -->
<h3 class="fn" id="toUnicode"><a name="toUnicode"></a><span class="type"><a href="qstring.html">QString</a></span> QTextCodec::<span class="name">toUnicode</span>(const <span class="type"><a href="qbytearray.html">QByteArray</a></span> &amp;<i>a</i>) const</h3>
<p>Converts <i>a</i> from the encoding of this codec to Unicode, and returns the result in a <a href="qstring.html">QString</a>.</p>
<!-- @@@toUnicode -->
<!-- $$$toUnicode$$$toUnicodeconstchar* -->
<h3 class="fn" id="toUnicode-1"><a name="toUnicode-1"></a><span class="type"><a href="qstring.html">QString</a></span> QTextCodec::<span class="name">toUnicode</span>(const <span class="type">char</span> *<i>chars</i>) const</h3>
<p>This is an overloaded function.</p>
<p><i>chars</i> contains the source characters.</p>
<!-- @@@toUnicode -->
<!-- $$$toUnicode$$$toUnicodeconstchar*intQTextCodec::ConverterState* -->
<h3 class="fn" id="toUnicode-2"><a name="toUnicode-2"></a><span class="type"><a href="qstring.html">QString</a></span> QTextCodec::<span class="name">toUnicode</span>(const <span class="type">char</span> *<i>input</i>, <span class="type">int</span> <i>size</i>, <span class="type"><a href="qtextcodec-converterstate.html">QTextCodec::ConverterState</a></span> *<i>state</i> = nullptr) const</h3>
<p>Converts the first <i>size</i> characters from the <i>input</i> from the encoding of this codec to Unicode, and returns the result in a <a href="qstring.html">QString</a>.</p>
<p>The <i>state</i> of the convertor used is updated.</p>
<!-- @@@toUnicode -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2018 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>