~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qtextcodec.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/corelib/codecs/qtextcodec.cpp -->
 
6
<head>
 
7
    <title>Qt 4.0: QTextCodec Class Reference</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QTextCodec Class Reference</h1>
 
21
<p>The QTextCodec class provides conversions between text encodings. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;QTextCodec&gt;</pre><p>Part of the <a href="qtcore.html">QtCore</a> module.</p>
 
23
<p><b>Note:</b> All the functions in this class are <a href="threads.html#reentrant">reentrant</a>, except <a href="qtextcodec.html#setCodecForTr">setCodecForTr</a>(), <a href="qtextcodec.html#setCodecForCStrings">setCodecForCStrings</a>(), <a href="qtextcodec.html#QTextCodec">QTextCodec</a>(), and <a href="qtextcodec.html#dtor.QTextCodec">~QTextCodec</a>().</p>
 
24
<ul>
 
25
<li><a href="qtextcodec-members.html">List of all members, including inherited members</a></li>
 
26
<li><a href="qtextcodec-qt3.html">Qt 3 support members</a></li>
 
27
</ul>
 
28
<a name="public-types"></a>
 
29
<h3>Public Types</h3>
 
30
<ul>
 
31
<li><div class="fn"/>class <b><a href="qtextcodec-converterstate.html">ConverterState</a></b></li>
 
32
<li><div class="fn"/>enum <b><a href="qtextcodec.html#ConversionFlag-enum">ConversionFlag</a></b> { DefaultConversion, ConvertInvalidToNull, IgnoreHeader }</li>
 
33
<li><div class="fn"/>flags <b><a href="qtextcodec.html#ConversionFlag-enum">ConversionFlags</a></b></li>
 
34
</ul>
 
35
<a name="public-functions"></a>
 
36
<h3>Public Functions</h3>
 
37
<ul>
 
38
<li><div class="fn"/>virtual QList&lt;QByteArray&gt; <b><a href="qtextcodec.html#aliases">aliases</a></b> () const</li>
 
39
<li><div class="fn"/>bool <b><a href="qtextcodec.html#canEncode">canEncode</a></b> ( QChar <i>ch</i> ) const</li>
 
40
<li><div class="fn"/>bool <b><a href="qtextcodec.html#canEncode-2">canEncode</a></b> ( const QString &amp; <i>s</i> ) const</li>
 
41
<li><div class="fn"/>QByteArray <b><a href="qtextcodec.html#fromUnicode">fromUnicode</a></b> ( const QString &amp; <i>str</i> ) const</li>
 
42
<li><div class="fn"/>QByteArray <b><a href="qtextcodec.html#fromUnicode-2">fromUnicode</a></b> ( const QChar * <i>input</i>, int <i>number</i>, ConverterState * <i>state</i> = 0 ) const</li>
 
43
<li><div class="fn"/>QTextDecoder * <b><a href="qtextcodec.html#makeDecoder">makeDecoder</a></b> () const</li>
 
44
<li><div class="fn"/>QTextEncoder * <b><a href="qtextcodec.html#makeEncoder">makeEncoder</a></b> () const</li>
 
45
<li><div class="fn"/>virtual int <b><a href="qtextcodec.html#mibEnum">mibEnum</a></b> () const = 0</li>
 
46
<li><div class="fn"/>virtual QByteArray <b><a href="qtextcodec.html#name">name</a></b> () const = 0</li>
 
47
<li><div class="fn"/>QString <b><a href="qtextcodec.html#toUnicode">toUnicode</a></b> ( const QByteArray &amp; <i>a</i> ) const</li>
 
48
<li><div class="fn"/>QString <b><a href="qtextcodec.html#toUnicode-2">toUnicode</a></b> ( const char * <i>input</i>, int <i>size</i>, ConverterState * <i>state</i> = 0 ) const</li>
 
49
<li><div class="fn"/>QString <b><a href="qtextcodec.html#toUnicode-4">toUnicode</a></b> ( const char * <i>chars</i> ) const</li>
 
50
</ul>
 
51
<a name="static-public-members"></a>
 
52
<h3>Static Public Members</h3>
 
53
<ul>
 
54
<li><div class="fn"/>QList&lt;QByteArray&gt; <b><a href="qtextcodec.html#availableCodecs">availableCodecs</a></b> ()</li>
 
55
<li><div class="fn"/>QList&lt;int&gt; <b><a href="qtextcodec.html#availableMibs">availableMibs</a></b> ()</li>
 
56
<li><div class="fn"/>QTextCodec * <b><a href="qtextcodec.html#codecForCStrings">codecForCStrings</a></b> ()</li>
 
57
<li><div class="fn"/>QTextCodec * <b><a href="qtextcodec.html#codecForLocale">codecForLocale</a></b> ()</li>
 
58
<li><div class="fn"/>QTextCodec * <b><a href="qtextcodec.html#codecForMib">codecForMib</a></b> ( int <i>mib</i> )</li>
 
59
<li><div class="fn"/>QTextCodec * <b><a href="qtextcodec.html#codecForName">codecForName</a></b> ( const QByteArray &amp; <i>name</i> )</li>
 
60
<li><div class="fn"/>QTextCodec * <b><a href="qtextcodec.html#codecForName-2">codecForName</a></b> ( const char * <i>name</i> )</li>
 
61
<li><div class="fn"/>QTextCodec * <b><a href="qtextcodec.html#codecForTr">codecForTr</a></b> ()</li>
 
62
<li><div class="fn"/>void <b><a href="qtextcodec.html#setCodecForCStrings">setCodecForCStrings</a></b> ( QTextCodec * <i>c</i> )</li>
 
63
<li><div class="fn"/>void <b><a href="qtextcodec.html#setCodecForLocale">setCodecForLocale</a></b> ( QTextCodec * <i>c</i> )</li>
 
64
<li><div class="fn"/>void <b><a href="qtextcodec.html#setCodecForTr">setCodecForTr</a></b> ( QTextCodec * <i>c</i> )</li>
 
65
</ul>
 
66
<a name="protected-functions"></a>
 
67
<h3>Protected Functions</h3>
 
68
<ul>
 
69
<li><div class="fn"/><b><a href="qtextcodec.html#QTextCodec">QTextCodec</a></b> ()</li>
 
70
<li><div class="fn"/>virtual <b><a href="qtextcodec.html#dtor.QTextCodec">~QTextCodec</a></b> ()</li>
 
71
<li><div class="fn"/>virtual QByteArray <b><a href="qtextcodec.html#convertFromUnicode">convertFromUnicode</a></b> ( const QChar * <i>input</i>, int <i>number</i>, ConverterState * <i>state</i> ) const = 0</li>
 
72
<li><div class="fn"/>virtual QString <b><a href="qtextcodec.html#convertToUnicode">convertToUnicode</a></b> ( const char * <i>chars</i>, int <i>len</i>, ConverterState * <i>state</i> ) const = 0</li>
 
73
</ul>
 
74
<a name="details"></a>
 
75
<hr />
 
76
<h2>Detailed Description</h2>
 
77
<p>The QTextCodec class provides conversions between text encodings.</p>
 
78
<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>
 
79
<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>
 
80
<p>The supported encodings are:</p>
 
81
<ul>
 
82
<li>Apple Roman</li>
 
83
<li>Big5</li>
 
84
<li>Big5-HKSCS</li>
 
85
<li>EUC-JP</li>
 
86
<li>EUC-KR</li>
 
87
<li>GB18030-0</li>
 
88
<li>IBM 850</li>
 
89
<li>IBM 866</li>
 
90
<li>IBM 874</li>
 
91
<li>ISO 2022-JP</li>
 
92
<li>ISO 8859-1 to 10</li>
 
93
<li>ISO 8859-13 to 16</li>
 
94
<li>Iscii-Bng, Dev, Gjr, Knd, Mlm, Ori, Pnj, Tlg, and Tml</li>
 
95
<li>JIS X 0201</li>
 
96
<li>JIS X 0208</li>
 
97
<li>KOI8-R</li>
 
98
<li>KOI8-U</li>
 
99
<li>MuleLao-1</li>
 
100
<li>ROMAN8</li>
 
101
<li>Shift-JIS</li>
 
102
<li>TIS-620</li>
 
103
<li>TSCII</li>
 
104
<li>UTF-8</li>
 
105
<li>UTF-16</li>
 
106
<li>UTF-16BE</li>
 
107
<li>UTF-16LE</li>
 
108
<li>Windows-1250 to 1258</li>
 
109
<li>WINSAMI2</li>
 
110
</ul>
 
111
<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>
 
112
<pre>&nbsp;   QByteArray encodedString = &quot;...&quot;;
 
113
    QTextCodec *codec = QTextCodec::codecForName(&quot;KOI8-R&quot;);
 
114
    QString string = codec-&gt;toUnicode(encodedString);</pre>
 
115
<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>
 
116
<pre>&nbsp;   QString string = &quot;...&quot;;
 
117
    QTextCodec *codec = QTextCodec::codecForName(&quot;KOI8-R&quot;);
 
118
    QByteArray encodedString = codec-&gt;fromUnicode(string);</pre>
 
119
<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>
 
120
<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>
 
121
<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>
 
122
<pre>&nbsp;   QTextCodec *codec = QTextCodec::codecForName(&quot;Shift-JIS&quot;);
 
123
    QTextDecoder *decoder = codec-&gt;makeDecoder();
 
124
 
 
125
    QString string;
 
126
    while (new_data_available()) {
 
127
        QByteArray chunk = get_new_data();
 
128
        string += decoder-&gt;toUnicode(chunk);
 
129
    }</pre>
 
130
<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>
 
131
<a name="creating-your-own-codec-class"></a>
 
132
<h3>Creating Your Own Codec Class</h3>
 
133
<p>Support for new text encodings can be added to Qt by creating QTextCodec subclasses.</p>
 
134
<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 <a href="winsystem.html#x11">X11</a>, for the locale-specific character input and output.</p>
 
135
<p>To add support for another encoding to Qt, make a subclass of QTextCodec and implement the functions listed in the table below.</p>
 
136
<table align="center" cellpadding="2" cellspacing="1" border="0">
 
137
<tr valign="top" bgcolor="#a2c511"><th>Function</th><th>Description</th></tr>
 
138
<tr valign="top" bgcolor="#f0f0f0"><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">IANA character-sets encoding file</a>, the name should be the preferred MIME name for the encoding.</td></tr>
 
139
<tr valign="top" bgcolor="#e0e0e0"><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, &quot;ISO-8859&quot; has &quot;latin1&quot;, &quot;US_ASCII&quot;, and &quot;iso-ir-100&quot; as aliases.</td></tr>
 
140
<tr valign="top" bgcolor="#f0f0f0"><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>
 
141
<tr valign="top" bgcolor="#e0e0e0"><td><a href="qtextcodec.html#convertToUnicode">convertToUnicode</a>()</td><td>Converts an 8-bit character string to Unicode.</td></tr>
 
142
<tr valign="top" bgcolor="#f0f0f0"><td><a href="qtextcodec.html#convertFromUnicode">convertFromUnicode</a>()</td><td>Converts a Unicode string to an 8-bit character string.</td></tr>
 
143
</table>
 
144
<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>
 
145
<p>See also <a href="qtextstream.html">QTextStream</a>, <a href="qtextdecoder.html">QTextDecoder</a>, and <a href="qtextencoder.html">QTextEncoder</a>.</p>
 
146
<hr />
 
147
<h2>Member Type Documentation</h2>
 
148
<h3 class="flags"><a name="ConversionFlag-enum"></a>enum QTextCodec::ConversionFlag<br />flags QTextCodec::ConversionFlags</h3>
 
149
<table border="1" cellpadding="2" cellspacing="1" width="100%">
 
150
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
 
151
<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>
 
152
<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>
 
153
<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>
 
154
</table>
 
155
<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>
 
156
<hr />
 
157
<h2>Member Function Documentation</h2>
 
158
<h3 class="fn"><a name="QTextCodec"></a>QTextCodec::QTextCodec ()&nbsp;&nbsp;<tt> [protected]</tt></h3>
 
159
<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>
 
160
<p><b>Warning:</b> This function is not <a href="threads.html#reentrant">reentrant</a>.</p>
 
161
<h3 class="fn"><a name="dtor.QTextCodec"></a>QTextCodec::~QTextCodec ()&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
 
162
<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>
 
163
<p><b>Warning:</b> This function is not <a href="threads.html#reentrant">reentrant</a>.</p>
 
164
<h3 class="fn"><a name="aliases"></a><a href="qlist.html">QList</a>&lt;<a href="qbytearray.html">QByteArray</a>&gt; QTextCodec::aliases () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
165
<p>Subclasses can return a number of aliases for the codec in question.</p>
 
166
<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>
 
167
<h3 class="fn"><a name="availableCodecs"></a><a href="qlist.html">QList</a>&lt;<a href="qbytearray.html">QByteArray</a>&gt; QTextCodec::availableCodecs ()&nbsp;&nbsp;<tt> [static]</tt></h3>
 
168
<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>
 
169
<p>The list may contain many mentions of the same codec if the codec has aliases.</p>
 
170
<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>
 
171
<h3 class="fn"><a name="availableMibs"></a><a href="qlist.html">QList</a>&lt;int&gt; QTextCodec::availableMibs ()&nbsp;&nbsp;<tt> [static]</tt></h3>
 
172
<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>
 
173
<p>See also <a href="qtextcodec.html#availableCodecs">availableCodecs</a>() and <a href="qtextcodec.html#mibEnum">mibEnum</a>().</p>
 
174
<h3 class="fn"><a name="canEncode"></a>bool QTextCodec::canEncode ( <a href="qchar.html">QChar</a> <i>ch</i> ) const</h3>
 
175
<p>Returns true if the Unicode character <i>ch</i> can be fully encoded with this codec; otherwise returns false.</p>
 
176
<h3 class="fn"><a name="canEncode-2"></a>bool QTextCodec::canEncode ( const <a href="qstring.html">QString</a> &amp; <i>s</i> ) const</h3>
 
177
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
178
<p><i>s</i> contains the string being tested for encode-ability.</p>
 
179
<h3 class="fn"><a name="codecForCStrings"></a>QTextCodec * QTextCodec::codecForCStrings ()&nbsp;&nbsp;<tt> [static]</tt></h3>
 
180
<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>
 
181
<p>See also <a href="qtextcodec.html#setCodecForCStrings">setCodecForCStrings</a>().</p>
 
182
<h3 class="fn"><a name="codecForLocale"></a>QTextCodec * QTextCodec::codecForLocale ()&nbsp;&nbsp;<tt> [static]</tt></h3>
 
183
<p>Returns a pointer to the codec most suitable for this locale.</p>
 
184
<h3 class="fn"><a name="codecForMib"></a>QTextCodec * QTextCodec::codecForMib ( int <i>mib</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
185
<p>Returns the <a href="qtextcodec.html">QTextCodec</a> which matches the <a href="qtextcodec.html#mibEnum">MIBenum</a> <i>mib</i>.</p>
 
186
<h3 class="fn"><a name="codecForName"></a>QTextCodec * QTextCodec::codecForName ( const <a href="qbytearray.html">QByteArray</a> &amp; <i>name</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
187
<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>
 
188
<h3 class="fn"><a name="codecForName-2"></a>QTextCodec * QTextCodec::codecForName ( const char * <i>name</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
189
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
190
<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>
 
191
<h3 class="fn"><a name="codecForTr"></a>QTextCodec * QTextCodec::codecForTr ()&nbsp;&nbsp;<tt> [static]</tt></h3>
 
192
<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>
 
193
<p>See also <a href="qtextcodec.html#setCodecForTr">setCodecForTr</a>().</p>
 
194
<h3 class="fn"><a name="convertFromUnicode"></a><a href="qbytearray.html">QByteArray</a> QTextCodec::convertFromUnicode ( const <a href="qchar.html">QChar</a> * <i>input</i>, int <i>number</i>, <a href="qtextcodec-converterstate.html">ConverterState</a> * <i>state</i> ) const&nbsp;&nbsp;<tt> [pure virtual protected]</tt></h3>
 
195
<p><a href="qtextcodec.html">QTextCodec</a> subclasses must reimplement this function.</p>
 
196
<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>
 
197
<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>
 
198
<h3 class="fn"><a name="convertToUnicode"></a><a href="qstring.html">QString</a> QTextCodec::convertToUnicode ( const char * <i>chars</i>, int <i>len</i>, <a href="qtextcodec-converterstate.html">ConverterState</a> * <i>state</i> ) const&nbsp;&nbsp;<tt> [pure virtual protected]</tt></h3>
 
199
<p><a href="qtextcodec.html">QTextCodec</a> subclasses must reimplement this function.</p>
 
200
<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>
 
201
<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>
 
202
<h3 class="fn"><a name="fromUnicode"></a><a href="qbytearray.html">QByteArray</a> QTextCodec::fromUnicode ( const <a href="qstring.html">QString</a> &amp; <i>str</i> ) const</h3>
 
203
<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>
 
204
<h3 class="fn"><a name="fromUnicode-2"></a><a href="qbytearray.html">QByteArray</a> QTextCodec::fromUnicode ( const <a href="qchar.html">QChar</a> * <i>input</i>, int <i>number</i>, <a href="qtextcodec-converterstate.html">ConverterState</a> * <i>state</i> = 0 ) const</h3>
 
205
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
206
<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>
 
207
<p>The <i>state</i> of the convertor used is updated.</p>
 
208
<h3 class="fn"><a name="makeDecoder"></a><a href="qtextdecoder.html">QTextDecoder</a> * QTextCodec::makeDecoder () const</h3>
 
209
<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>
 
210
<p>The caller is responsible for deleting the returned object.</p>
 
211
<h3 class="fn"><a name="makeEncoder"></a><a href="qtextencoder.html">QTextEncoder</a> * QTextCodec::makeEncoder () const</h3>
 
212
<p>Creates a <a href="qtextencoder.html">QTextEncoder</a> which stores enough state to encode chunks of Unicode data as char* data.</p>
 
213
<p>The caller is responsible for deleting the returned object.</p>
 
214
<h3 class="fn"><a name="mibEnum"></a>int QTextCodec::mibEnum () const&nbsp;&nbsp;<tt> [pure virtual]</tt></h3>
 
215
<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>
 
216
<h3 class="fn"><a name="name"></a><a href="qbytearray.html">QByteArray</a> QTextCodec::name () const&nbsp;&nbsp;<tt> [pure virtual]</tt></h3>
 
217
<p><a href="qtextcodec.html">QTextCodec</a> subclasses must reimplement this function. It returns the name of the encoding supported by the subclass.</p>
 
218
<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 it's name.</p>
 
219
<h3 class="fn"><a name="setCodecForCStrings"></a>void QTextCodec::setCodecForCStrings ( QTextCodec * <i>c</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
220
<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>
 
221
<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>
 
222
<p><b>Warning:</b> This function is not <a href="threads.html#reentrant">reentrant</a>.</p>
 
223
<p>See also <a href="qtextcodec.html#codecForCStrings">codecForCStrings</a>() and <a href="qtextcodec.html#setCodecForTr">setCodecForTr</a>().</p>
 
224
<h3 class="fn"><a name="setCodecForLocale"></a>void QTextCodec::setCodecForLocale ( QTextCodec * <i>c</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
225
<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>
 
226
<p>See also <a href="qtextcodec.html#codecForLocale">codecForLocale</a>().</p>
 
227
<h3 class="fn"><a name="setCodecForTr"></a>void QTextCodec::setCodecForTr ( QTextCodec * <i>c</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
228
<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>
 
229
<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>
 
230
<pre>&nbsp;   int main(int argc, char** argv)
 
231
    {
 
232
        QApplication app(argc, argv);
 
233
        ... install any additional codecs ...
 
234
        QTextCodec::setCodecForTr(QTextCodec::codecForName(&quot;eucKR&quot;));
 
235
        ...
 
236
    }</pre>
 
237
<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>
 
238
<p><b>Warning:</b> This function is not <a href="threads.html#reentrant">reentrant</a>.</p>
 
239
<p>See also <a href="qtextcodec.html#codecForTr">codecForTr</a>() and <a href="qtextcodec.html#setCodecForCStrings">setCodecForCStrings</a>().</p>
 
240
<h3 class="fn"><a name="toUnicode"></a><a href="qstring.html">QString</a> QTextCodec::toUnicode ( const <a href="qbytearray.html">QByteArray</a> &amp; <i>a</i> ) const</h3>
 
241
<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>
 
242
<h3 class="fn"><a name="toUnicode-2"></a><a href="qstring.html">QString</a> QTextCodec::toUnicode ( const char * <i>input</i>, int <i>size</i>, <a href="qtextcodec-converterstate.html">ConverterState</a> * <i>state</i> = 0 ) const</h3>
 
243
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
244
<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>
 
245
<p>The <i>state</i> of the convertor used is updated.</p>
 
246
<h3 class="fn"><a name="toUnicode-4"></a><a href="qstring.html">QString</a> QTextCodec::toUnicode ( const char * <i>chars</i> ) const</h3>
 
247
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
248
<p><i>chars</i> contains the source characters.</p>
 
249
<p /><address><hr /><div align="center">
 
250
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
251
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
252
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
253
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
254
</tr></table></div></address></body>
 
255
</html>