Sophie

Sophie

distrib > Mandriva > current > i586 > media > main-updates > by-pkgid > 8e6051afcdb111a0317a58fb64c2abf5 > files > 6175

qt4-doc-4.6.3-0.2mdv2010.2.i586.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- unicode.qdoc -->
<head>
  <title>Qt 4.6: Unicode in Qt</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
<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="functions.html"><font color="#004faf">All&nbsp;Functions</font></a>&nbsp;&middot; <a href="overviews.html"><font color="#004faf">Overviews</font></a></td></tr></table><h1 class="title">Unicode in Qt<br /><span class="subtitle"></span>
</h1>
<a name="unicode"></a><p>Unicode is a multi-byte character set, portable across all major computing platforms and with decent coverage over most of the world. It is also single-locale; it includes no code pages or other complexities that make software harder to write and test. There is no competing character set that's reasonably cross-platform. For these reasons, Unicode 4.0 is used as the native character set for Qt.</p>
<a name="qt-s-classes-for-working-with-strings"></a>
<h3>Qt's Classes for Working with Strings</h3>
<p>These classes are relevant when working with string data. For information about rendering text, see the <a href="richtext.html">Rich Text Processing</a> overview, and if your string data is in XML, see the <a href="xml-processing.html">XML Processing</a> overview.</p>
<p><table width="100%" class="annotated" cellpadding="2" cellspacing="1" border="0">
<tr valign="top" class="odd"><th><a href="qbytearray.html">QByteArray</a></th><td>Array of bytes</td></tr>
<tr valign="top" class="even"><th><a href="qbytearraymatcher.html">QByteArrayMatcher</a></th><td>Holds a sequence of bytes that can be quickly matched in a byte array</td></tr>
<tr valign="top" class="odd"><th><a href="qchar.html">QChar</a></th><td>16-bit Unicode character</td></tr>
<tr valign="top" class="even"><th><a href="qlatin1char.html">QLatin1Char</a></th><td>8-bit ASCII/Latin-1 character</td></tr>
<tr valign="top" class="odd"><th><a href="qlatin1string.html">QLatin1String</a></th><td>Thin wrapper around an ASCII/Latin-1 encoded string literal</td></tr>
<tr valign="top" class="even"><th><a href="qlocale.html">QLocale</a></th><td>Converts between numbers and their string representations in various languages</td></tr>
<tr valign="top" class="odd"><th><a href="qstring.html">QString</a></th><td>Unicode character string</td></tr>
<tr valign="top" class="even"><th><a href="qstringlist.html">QStringList</a></th><td>List of strings</td></tr>
<tr valign="top" class="odd"><th><a href="qstringmatcher.html">QStringMatcher</a></th><td>Holds a sequence of characters that can be quickly matched in a Unicode string</td></tr>
<tr valign="top" class="even"><th><a href="qstringref.html">QStringRef</a></th><td>Thin wrapper around QString substrings</td></tr>
<tr valign="top" class="odd"><th><a href="qtextboundaryfinder.html">QTextBoundaryFinder</a></th><td>Way of finding Unicode text boundaries in a string</td></tr>
<tr valign="top" class="even"><th><a href="qtextstream.html">QTextStream</a></th><td>Convenient interface for reading and writing text</td></tr>
</table></p>
<a name="information-about-unicode-on-the-web"></a>
<h3>Information about Unicode on the Web</h3>
<p>The <a href="http://www.unicode.org/">Unicode Consortium</a> has a number of documents available, including</p>
<ul>
<li><a href="http://www.unicode.org/unicode/standard/principles.html">A technical introduction to Unicode</a></li>
<li><a href="http://www.unicode.org/unicode/standard/standard.html">The home page for the standard</a></li>
</ul>
<a name="the-standard"></a>
<h3>The Standard</h3>
<p>The current version of the standard is <a href="http://www.unicode.org/versions/Unicode5.1.0/">Unicode 5.1&#x2e;0</a>.</p>
<p>Previous printed versions of the specification:</p>
<ul>
<li><a href="http://www.amazon.com/Unicode-Standard-Version-5-0-5th/dp/0321480910/trolltech/t">The Unicode Standard, Version 5.0</a></li>
<li><a href="http://www.amazon.com/exec/obidos/ASIN/0321185781/trolltech/t">The Unicode Standard, version 4.0</a></li>
<li><a href="http://www.amazon.com/exec/obidos/ASIN/0201616335/trolltech/t">The Unicode Standard, version 3.2</a></li>
<li><a href="http://www.amazon.com/exec/obidos/ASIN/0201473459/trolltech/t">The Unicode Standard, version 2.0</a> &mdash; see also the <a href="http://www.unicode.org/unicode/reports/tr8.html">2.1 update</a> and <a href="http://www.unicode.org/unicode/standard/versions/enumeratedversions.html#Unicode 2.1.9">the 2.1&#x2e;9 data files</a> at <a href="http://www.unicode.org">http://www.unicode.org</a>.</li>
</ul>
<a name="unicode-in-qt"></a>
<h3>Unicode in Qt</h3>
<p>In Qt, and in most applications that use Qt, most or all user-visible strings are stored using Unicode. Qt provides:</p>
<ul>
<li>Translation to/from legacy encodings for file I/O: see <a href="qtextcodec.html">QTextCodec</a> and <a href="qtextstream.html">QTextStream</a>.</li>
<li>Translation from Input Methods and 8-bit keyboard input.</li>
<li>Translation to legacy character sets for on-screen display.</li>
<li>A string class, <a href="qstring.html">QString</a>, that stores Unicode characters, with support for migrating from C strings including fast (cached) translation to and from US-ASCII, and all the usual string operations.</li>
<li>Unicode-aware widgets where appropriate.</li>
<li>Unicode support detection on Windows, so that Qt provides Unicode even on Windows platforms that do not support it natively.</li>
</ul>
<p>To fully benefit from Unicode, we recommend using <a href="qstring.html">QString</a> for storing all user-visible strings, and performing all text file I/O using <a href="qtextstream.html">QTextStream</a>. Use <a href="qkeyevent.html#text">QKeyEvent::text</a>() for keyboard input in any custom widgets you write; it does not make much difference for slow typists in Western Europe or North America, but for fast typists or people using special input methods using text() is beneficial.</p>
<p>All the function arguments in Qt that may be user-visible strings, <a href="qlabel.html#text-prop">QLabel::setText</a>() and a many others, take <tt>const QString &amp;</tt>s. <a href="qstring.html">QString</a> provides implicit casting from <tt>const char *</tt> so that things like</p>
<pre> label-&gt;setText(&quot;Password:&quot;);</pre>
<p>will work. There is also a function, <a href="qobject.html#tr">QObject::tr</a>(), that provides translation support, like this:</p>
<pre> label-&gt;setText(tr(&quot;Password:&quot;));</pre>
<p><a href="qobject.html#tr">QObject::tr</a>() maps from <tt>const char *</tt> to a Unicode string, and uses installable <a href="qtranslator.html">QTranslator</a> objects to do the mapping.</p>
<p>Qt provides a number of built-in <a href="qtextcodec.html">QTextCodec</a> classes, that is, classes that know how to translate between Unicode and legacy encodings to support programs that must talk to other programs or read/write files in legacy file formats.</p>
<p>By default, conversion to/from <tt>const char *</tt> uses a locale-dependent codec. However, applications can easily find codecs for other locales, and set any open file or network connection to use a special codec. It is also possible to install new codecs, for encodings that the built-in ones do not support. (At the time of writing, Vietnamese/VISCII is one such example.)</p>
<p>Since US-ASCII and ISO-8859-1 are so common, there are also especially fast functions for mapping to and from them. For example, to open an application's icon one might do this:</p>
<pre> QFile file(QString::fromLatin1(&quot;appicon.png&quot;));</pre>
<p>or</p>
<pre> QFile file(QLatin1String(&quot;appicon.png&quot;));</pre>
<p>Regarding output, Qt will do a best-effort conversion from Unicode to whatever encoding the system and fonts provide. Depending on operating system, locale, font availability, and Qt's support for the characters used, this conversion may be good or bad. We will extend this in upcoming versions, with emphasis on the most common locales first.</p>
<p>See also <a href="internationalization.html">Internationalization with Qt</a>.</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="40%" align="left">Copyright &copy; 2010 Nokia Corporation and/or its subsidiary(-ies)</td>
<td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="40%" align="right"><div align="right">Qt 4.6.3</div></td>
</tr></table></div></address></body>
</html>