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
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QTextCodec Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QTextCodec Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QTextCodec class provides conversions between text encodings. <a href="#details">More...</a></p>
<h3>Types</h3><ul><li><div class="fn" />enum <b><a href="qtextcodec.html#ConversionFlag-enum">ConversionFlag</a></b> { DefaultConversion, ConvertInvalidToNull, IgnoreHeader }</li><li><div class="fn" />class <b><a href="qtextcodec-conversionflags.html">ConversionFlags</a></b></li><li><div class="fn" />class <b><a href="qtextcodec-converterstate.html">ConverterState</a></b></li></ul><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qtextcodec.html#QTextCodec">__init__</a></b> (<i>self</i>)</li><li><div class="fn" />QByteArray-list <b><a href="qtextcodec.html#aliases">aliases</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qtextcodec.html#canEncode">canEncode</a></b> (<i>self</i>, QChar)</li><li><div class="fn" />bool <b><a href="qtextcodec.html#canEncode-2">canEncode</a></b> (<i>self</i>, QString)</li><li><div class="fn" />QByteArray <b><a href="qtextcodec.html#convertFromUnicode">convertFromUnicode</a></b> (<i>self</i>, QChar <i>in</i>, int <i>length</i>, ConverterState <i>state</i>)</li><li><div class="fn" />QString <b><a href="qtextcodec.html#convertToUnicode">convertToUnicode</a></b> (<i>self</i>, str <i>in</i>, ConverterState <i>state</i>)</li><li><div class="fn" />QByteArray <b><a href="qtextcodec.html#fromUnicode">fromUnicode</a></b> (<i>self</i>, QString <i>uc</i>)</li><li><div class="fn" />QByteArray <b><a href="qtextcodec.html#fromUnicode-2">fromUnicode</a></b> (<i>self</i>, QChar <i>in</i>, int <i>length</i>, ConverterState <i>state</i> = None)</li><li><div class="fn" />QTextDecoder <b><a href="qtextcodec.html#makeDecoder">makeDecoder</a></b> (<i>self</i>)</li><li><div class="fn" />QTextEncoder <b><a href="qtextcodec.html#makeEncoder">makeEncoder</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qtextcodec.html#mibEnum">mibEnum</a></b> (<i>self</i>)</li><li><div class="fn" />QByteArray <b><a href="qtextcodec.html#name">name</a></b> (<i>self</i>)</li><li><div class="fn" />QString <b><a href="qtextcodec.html#toUnicode">toUnicode</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" />QString <b><a href="qtextcodec.html#toUnicode-2">toUnicode</a></b> (<i>self</i>, str <i>chars</i>)</li><li><div class="fn" />QString <b><a href="qtextcodec.html#toUnicode-3">toUnicode</a></b> (<i>self</i>, str <i>in</i>, ConverterState <i>state</i> = None)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />QByteArray-list <b><a href="qtextcodec.html#availableCodecs">availableCodecs</a></b> ()</li><li><div class="fn" />int-list <b><a href="qtextcodec.html#availableMibs">availableMibs</a></b> ()</li><li><div class="fn" />QTextCodec <b><a href="qtextcodec.html#codecForCStrings">codecForCStrings</a></b> ()</li><li><div class="fn" />QTextCodec <b><a href="qtextcodec.html#codecForHtml">codecForHtml</a></b> (QByteArray <i>ba</i>)</li><li><div class="fn" />QTextCodec <b><a href="qtextcodec.html#codecForLocale">codecForLocale</a></b> ()</li><li><div class="fn" />QTextCodec <b><a href="qtextcodec.html#codecForMib">codecForMib</a></b> (int <i>mib</i>)</li><li><div class="fn" />QTextCodec <b><a href="qtextcodec.html#codecForName">codecForName</a></b> (QByteArray <i>name</i>)</li><li><div class="fn" />QTextCodec <b><a href="qtextcodec.html#codecForName-2">codecForName</a></b> (str <i>name</i>)</li><li><div class="fn" />QTextCodec <b><a href="qtextcodec.html#codecForTr">codecForTr</a></b> ()</li><li><div class="fn" /><b><a href="qtextcodec.html#setCodecForCStrings">setCodecForCStrings</a></b> (QTextCodec <i>c</i>)</li><li><div class="fn" /><b><a href="qtextcodec.html#setCodecForLocale">setCodecForLocale</a></b> (QTextCodec <i>c</i>)</li><li><div class="fn" /><b><a href="qtextcodec.html#setCodecForTr">setCodecForTr</a></b> (QTextCodec <i>c</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QTextCodec 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 QTextCodec 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>Apple Roman</li>
<li><a href="codec-big5.html">Big5</a></li>
<li><a href="codec-big5hkscs.html">Big5-HKSCS</a></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-0</a></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>JIS X 0201</li>
<li>JIS X 0208</li>
<li>KOI8-R</li>
<li>KOI8-U</li>
<li>MuleLao-1</li>
<li>ROMAN8</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>Windows-1250 to 1258</li>
<li>WINSAMI2</li>
</ul>
<p>QTextCodecs 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>
QByteArray encodedString = "...";
QTextCodec *codec = QTextCodec.codecForName("KOI8-R");
QString string = codec->toUnicode(encodedString);
</pre>
<p>After this, <tt>string</tt> holds the text converted to Unicode. Converting a string from Unicode to the local encoding is just as easy:</p>
<pre>
QString string = "...";
QTextCodec *codec = QTextCodec.codecForName("KOI8-R");
QByteArray encodedString = codec->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="tools-codecs.html">Codecs</a> example for an application of QTextCodec 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>
QTextCodec *codec = QTextCodec.codecForName("Shift-JIS");
QTextDecoder *decoder = codec->makeDecoder();
QString string;
while (new_data_available()) {
QByteArray chunk = get_new_data();
string += decoder->toUnicode(chunk);
}
</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 id="creating-your-own-codec-class" name="creating-your-own-codec-class" />
<h3>Creating Your Own Codec Class</h3>
<p>Support for new text encodings can be added to Qt by creating QTextCodec 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 QTextCodec and implement the functions listed in the table below.</p>
<table align="center" border="0" cellpadding="2" cellspacing="1">
<tr bgcolor="#A2C511" valign="top">
<th>Function</th>
<th>Description</th>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<td><a href="qtextcodec.html#name">name</a>()</td>
<td>Returns the official name for the encoding. If the ncoding is listed in the <a href="http://www.iana.org/assignments/character-sets">IANA character-sets encoding file</a>, the name should be the preferred MIME name for the encoding.</td>
</tr>
<tr bgcolor="#E0E0E0" valign="top">
<td><a href="qtextcodec.html#aliases">aliases</a>()</td>
<td>Returns a list of alternative names for the encoding. QTextCodec provides a default implementation that returns an empty list. For example, "ISO-8859-1" has "latin1", "CP819", "IBM819", and "iso-ir-100" as aliases.</td>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<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">IANA character-sets encoding file</a>.</td>
</tr>
<tr bgcolor="#E0E0E0" valign="top">
<td><a href="qtextcodec.html#convertToUnicode">convertToUnicode</a>()</td>
<td>Converts an 8-bit character string to Unicode.</td>
</tr>
<tr bgcolor="#F0F0F0" valign="top">
<td><a href="qtextcodec.html#convertFromUnicode">convertFromUnicode</a>()</td>
<td>Converts a Unicode string to an 8-bit character string.</td>
</tr>
</table>
<br />
<br />
<p>You may find it more convenient to make your codec class available as a plugin; see <a href="plugins-howto.html">How to Create Qt Plugins</a> for details.</p>
<p>See also <a href="qtextstream.html">QTextStream</a>, <a href="qtextdecoder.html">QTextDecoder</a>, and <a href="qtextencoder.html">QTextEncoder</a>.</p>
<hr /><h2>Type Documentation</h2><h3 class="fn"><a name="ConversionFlag-enum" />QTextCodec.ConversionFlag</h3><table border="1" cellpadding="2" cellspacing="1" width="100%">
<tr>
<th width="25%">Constant</th>
<th width="15%">Value</th>
<th width="60%">Description</th>
</tr>
<tr>
<td valign="top"><tt>QTextCodec.DefaultConversion</tt></td>
<td align="center" valign="top"><tt>0</tt></td>
<td valign="top">No flag is set.</td>
</tr>
<tr>
<td valign="top"><tt>QTextCodec.ConvertInvalidToNull</tt></td>
<td align="center" valign="top"><tt>0x80000000</tt></td>
<td valign="top">If this flag is set, invalid input results in an empty string.</td>
</tr>
<tr>
<td valign="top"><tt>QTextCodec.IgnoreHeader</tt></td>
<td align="center" valign="top"><tt>0x1</tt></td>
<td valign="top">Ignore any Unicode byte-order mark and don't generate any.</td>
</tr>
</table>
<br />
<br />
<p>The ConversionFlags type is a typedef for <a href="qflags.html">QFlags</a><ConversionFlag>. It stores an OR combination of ConversionFlag values.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QTextCodec" />QTextCodec.__init__ (<i>self</i>)</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. with <tt>new</tt>). Qt takes ownership and will delete it when the application terminates.</p>
<p><b>Warning:</b> This function is not <a href="threads.html#reentrant">reentrant</a>.</p>
<h3 class="fn"><a name="aliases" />QByteArray-list QTextCodec.aliases (<i>self</i>)</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">IANA character-sets encoding file</a>.</p>
<h3 class="fn"><a name="availableCodecs" />QByteArray-list QTextCodec.availableCodecs ()</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>See also <a href="qtextcodec.html#availableMibs">availableMibs</a>(), <a href="qtextcodec.html#name">name</a>(), and <a href="qtextcodec.html#aliases">aliases</a>().</p>
<h3 class="fn"><a name="availableMibs" />int-list QTextCodec.availableMibs ()</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>See also <a href="qtextcodec.html#availableCodecs">availableCodecs</a>() and <a href="qtextcodec.html#mibEnum">mibEnum</a>().</p>
<h3 class="fn"><a name="canEncode" />bool QTextCodec.canEncode (<i>self</i>, <a href="qchar.html">QChar</a>)</h3><p>Returns true if the Unicode character <i>ch</i> can be fully encoded with this codec; otherwise returns false.</p>
<h3 class="fn"><a name="canEncode-2" />bool QTextCodec.canEncode (<i>self</i>, <a href="qstring.html">QString</a>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<p><i>s</i> contains the string being tested for encode-ability.</p>
<h3 class="fn"><a name="codecForCStrings" /><a href="qtextcodec.html">QTextCodec</a> QTextCodec.codecForCStrings ()</h3><p>Returns the codec used by <a href="qstring.html">QString</a> to convert to and from <tt>const char*</tt> and QByteArrays. If this function returns 0 (the default), <a href="qstring.html">QString</a> assumes Latin1.</p>
<p>See also <a href="qtextcodec.html#setCodecForCStrings">setCodecForCStrings</a>().</p>
<h3 class="fn"><a name="codecForHtml" /><a href="qtextcodec.html">QTextCodec</a> QTextCodec.codecForHtml (<a href="qbytearray.html">QByteArray</a> <i>ba</i>)</h3><h3 class="fn"><a name="codecForLocale" /><a href="qtextcodec.html">QTextCodec</a> QTextCodec.codecForLocale ()</h3><p>Returns a pointer to the codec most suitable for this locale.</p>
<p>See also <a href="qtextcodec.html#setCodecForLocale">setCodecForLocale</a>().</p>
<h3 class="fn"><a name="codecForMib" /><a href="qtextcodec.html">QTextCodec</a> QTextCodec.codecForMib (int <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>
<h3 class="fn"><a name="codecForName" /><a href="qtextcodec.html">QTextCodec</a> QTextCodec.codecForName (<a href="qbytearray.html">QByteArray</a> <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>
<h3 class="fn"><a name="codecForName-2" /><a href="qtextcodec.html">QTextCodec</a> QTextCodec.codecForName (str <i>name</i>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<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>
<h3 class="fn"><a name="codecForTr" /><a href="qtextcodec.html">QTextCodec</a> QTextCodec.codecForTr ()</h3><p>Returns the codec used by <a href="qobject.html#tr">QObject.tr</a>() on its argument. If this function returns 0 (the default), tr() assumes Latin1.</p>
<p>See also <a href="qtextcodec.html#setCodecForTr">setCodecForTr</a>().</p>
<h3 class="fn"><a name="convertFromUnicode" /><a href="qbytearray.html">QByteArray</a> QTextCodec.convertFromUnicode (<i>self</i>, <a href="qchar.html">QChar</a> <i>in</i>, int <i>length</i>, <a href="qtextcodec-converterstate.html">ConverterState</a> <i>state</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><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 remainingChars and invalidChars members of the struct.</p>
<h3 class="fn"><a name="convertToUnicode" /><a href="qstring.html">QString</a> QTextCodec.convertToUnicode (<i>self</i>, str <i>in</i>, <a href="qtextcodec-converterstate.html">ConverterState</a> <i>state</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><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 remainingChars and invalidChars members of the struct.</p>
<h3 class="fn"><a name="fromUnicode" /><a href="qbytearray.html">QByteArray</a> QTextCodec.fromUnicode (<i>self</i>, <a href="qstring.html">QString</a> <i>uc</i>)</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>
<h3 class="fn"><a name="fromUnicode-2" /><a href="qbytearray.html">QByteArray</a> QTextCodec.fromUnicode (<i>self</i>, <a href="qchar.html">QChar</a> <i>in</i>, int <i>length</i>, <a href="qtextcodec-converterstate.html">ConverterState</a> <i>state</i> = None)</h3><p>This is an overloaded member function, provided for convenience.</p>
<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>
<h3 class="fn"><a name="makeDecoder" /><a href="qtextdecoder.html">QTextDecoder</a> QTextCodec.makeDecoder (<i>self</i>)</h3><p>Creates a <a href="qtextdecoder.html">QTextDecoder</a> which stores enough state to decode chunks of char* data to create chunks of Unicode data.</p>
<p>The caller is responsible for deleting the returned object.</p>
<h3 class="fn"><a name="makeEncoder" /><a href="qtextencoder.html">QTextEncoder</a> QTextCodec.makeEncoder (<i>self</i>)</h3><p>Creates a <a href="qtextencoder.html">QTextEncoder</a> which stores enough state to encode chunks of Unicode data as char* data.</p>
<p>The caller is responsible for deleting the returned object.</p>
<h3 class="fn"><a name="mibEnum" />int QTextCodec.mibEnum (<i>self</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><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">the 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>
<h3 class="fn"><a name="name" /><a href="qbytearray.html">QByteArray</a> QTextCodec.name (<i>self</i>)</h3><p>This method is abstract and should be reimplemented in any sub-class.</p><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">IANA character-sets encoding file</a> this method should return the preferred mime name for the codec if defined, otherwise its name.</p>
<h3 class="fn"><a name="setCodecForCStrings" />QTextCodec.setCodecForCStrings (<a href="qtextcodec.html">QTextCodec</a> <i>c</i>)</h3><p>Sets the codec used by <a href="qstring.html">QString</a> to convert to and from <tt>const char*</tt> and QByteArrays. If <i>c</i> is 0 (the default), <a href="qstring.html">QString</a> assumes Latin1.</p>
<p><b>Warning:</b> Some codecs do not preserve the characters in the ASCII range (0x00 to 0x7f). For example, the Japanese Shift-JIS encoding maps the backslash character (0x5a) to the Yen character. This leads to unexpected results when using the backslash character to escape characters in strings used in e.g. regular expressions. Use <a href="qstring.html#fromLatin1">QString.fromLatin1</a>() to preserve characters in the ASCII range when needed.</p>
<p><b>Warning:</b> This function is not <a href="threads.html#reentrant">reentrant</a>.</p>
<p>See also <a href="qtextcodec.html#codecForCStrings">codecForCStrings</a>() and <a href="qtextcodec.html#setCodecForTr">setCodecForTr</a>().</p>
<h3 class="fn"><a name="setCodecForLocale" />QTextCodec.setCodecForLocale (<a href="qtextcodec.html">QTextCodec</a> <i>c</i>)</h3><p>Set the codec to <i>c</i>; this will be returned by <a href="qtextcodec.html#codecForLocale">codecForLocale</a>(). This might be needed for some applications that want to use their own mechanism for setting the locale.</p>
<p>Setting this codec is not supported on DOS based Windows.</p>
<p>See also <a href="qtextcodec.html#codecForLocale">codecForLocale</a>().</p>
<h3 class="fn"><a name="setCodecForTr" />QTextCodec.setCodecForTr (<a href="qtextcodec.html">QTextCodec</a> <i>c</i>)</h3><p>Sets the codec used by <a href="qobject.html#tr">QObject.tr</a>() on its argument to <i>c</i>. If <i>c</i> is 0 (the default), tr() assumes Latin1.</p>
<p>If the literal quoted text in the program is not in the Latin1 encoding, this function can be used to set the appropriate encoding. For example, software developed by Korean programmers might use eucKR for all the text in the program, in which case the main() function might look like this:</p>
<pre>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
... install any additional codecs ...
QTextCodec.setCodecForTr(QTextCodec.codecForName("eucKR"));
...
}
</pre>
<p>Note that this is not the way to select the encoding that the <i>user</i> has chosen. For example, to convert an application containing literal English strings to Korean, all that is needed is for the English strings to be passed through tr() and for translation files to be loaded. For details of internationalization, see <a href="i18n.html">Internationalization with Qt</a>.</p>
<p><b>Warning:</b> This function is not <a href="threads.html#reentrant">reentrant</a>.</p>
<p>See also <a href="qtextcodec.html#codecForTr">codecForTr</a>() and <a href="qtextcodec.html#setCodecForCStrings">setCodecForCStrings</a>().</p>
<h3 class="fn"><a name="toUnicode" /><a href="qstring.html">QString</a> QTextCodec.toUnicode (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</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>
<h3 class="fn"><a name="toUnicode-2" /><a href="qstring.html">QString</a> QTextCodec.toUnicode (<i>self</i>, str <i>chars</i>)</h3><p>This is an overloaded member function, provided for convenience.</p>
<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>
<h3 class="fn"><a name="toUnicode-3" /><a href="qstring.html">QString</a> QTextCodec.toUnicode (<i>self</i>, str <i>in</i>, <a href="qtextcodec-converterstate.html">ConverterState</a> <i>state</i> = None)</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td width="25%">PyQt 4.0.1 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.trolltech.com">Trolltech AS</a> 2006</td><td align="right" width="25%">Qt 4.1.4</td></tr></table></div></address></body></html>
|