Sophie

Sophie

distrib > Mageia > 6 > i586 > by-pkgid > f93881942bd3805980c2fe63aa853d78 > files > 287

qtdoc5-5.9.4-1.mga6.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- unicode.qdoc -->
  <title>Unicode in Qt | Qt 5.9</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="index.html">Qt 5.9</a></td><td >Unicode in Qt</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.9.4 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="#qt-s-classes-for-working-with-strings">Qt's Classes for Working with Strings</a></li>
<li class="level1"><a href="#information-about-unicode-on-the-web">Information about Unicode on the Web</a></li>
<li class="level1"><a href="#unicode-in-qt">Unicode in Qt</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Unicode in Qt</h1>
<span class="subtitle"></span>
<!-- $$$unicode.html-description -->
<div class="descr"> <a name="details"></a>
<p><a href="http://www.unicode.org/">Unicode</a> is the standard for encoding text in almost all languages spoken in the world. It is nowadays used as the native encoding for text on most modern operating systems. The major exception is Microsoft Windows that still has a dual system supporting code pages and Unicode for applications.</p>
<p>Qt 5.0 uses and fully supports version 6.2 of the Unicode standard.</p>
<a name="qt-s-classes-for-working-with-strings"></a>
<h2 id="qt-s-classes-for-working-with-strings">Qt's Classes for Working with Strings</h2>
<p>These classes are relevant when working with string data. For information about rendering text, see the Rich Text Processing overview, and if your string data is in XML, see the XML Processing overview.</p>
<a name="information-about-unicode-on-the-web"></a>
<h2 id="information-about-unicode-on-the-web">Information about Unicode on the Web</h2>
<p>The <a href="http://www.unicode.org/">Unicode Consortium</a> has a number of documents available, including</p>
<ul>
<li>The current version of the standard: <a href="http://www.unicode.org/versions/Unicode6.2.0/">Unicode 6.2&#x2e;0</a>.</li>
<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="unicode-in-qt"></a>
<h2 id="unicode-in-qt">Unicode in Qt</h2>
<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 QTextCodec and QTextStream.</li>
<li>Support for locale specific Input Methods and keyboards.</li>
<li>A string class, QString, that stores Unicode characters, with support for migrating from C strings including fast translation to and from UTF-8, ISO8859-1 and US-ASCII, and all the usual string operations.</li>
<li>Unicode-aware UI controls.</li>
<li>Unicode compliant text segmentation (QTextBoundaryFinder)</li>
<li>Unicode compliant line breaking and text rendering</li>
</ul>
<p>To fully benefit from Unicode, we recommend using QString for storing all user-visible strings, and performing all text file I/O using QTextStream.</p>
<p>All the function arguments in Qt that may be user-visible strings, QLabel::setText() and a many others, take <code>const QString &amp;</code>s. QString provides implicit casting from <code>const char *</code> so that things like</p>
<pre class="cpp">

  label<span class="operator">-</span><span class="operator">&gt;</span>setText(<span class="string">&quot;Password:&quot;</span>);

</pre>
<p>will work. There is also a function, QObject::tr(), that provides translation support, like this:</p>
<pre class="cpp">

  label<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Password:&quot;</span>));

</pre>
<p>QObject::tr() maps from <code>const char *</code> to a Unicode string, and uses installable QTranslator objects to do the mapping.</p>
<p>Qt provides a number of built-in QTextCodec 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>Conversion to/from <code>const char *</code> uses a UTF-8. However, applications can easily find codecs for other locales, and set any open file or network connection to use a special codec.</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 class="cpp">

  <span class="type">QFile</span> file(<span class="type">QString</span><span class="operator">::</span>fromLatin1(<span class="string">&quot;appicon.png&quot;</span>));

</pre>
<p>or</p>
<pre class="cpp">

  <span class="type">QFile</span> file(QLatin1String(<span class="string">&quot;appicon.png&quot;</span>));

</pre>
<p>Qt supports rendering text in most languages written in the world. The detailed list of supported writing systems depends a bit on operating system support and font availability on the target system.</p>
</div>
<p><b>See also </b><a href="internationalization.html">Internationalization with Qt</a>.</p>
<!-- @@@unicode.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2017 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>