1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | /*!
|
---|
43 | \page unicode.html
|
---|
44 | \title Unicode
|
---|
45 | \ingroup architecture
|
---|
46 | \ingroup text-processing
|
---|
47 | \brief Information about support for Unicode in Qt.
|
---|
48 |
|
---|
49 | Unicode is a multi-byte character set, portable across all major
|
---|
50 | computing platforms and with decent coverage over most of the world.
|
---|
51 | It is also single-locale; it includes no code pages or other
|
---|
52 | complexities that make software harder to write and test. There is no
|
---|
53 | competing character set that's reasonably cross-platform. For these
|
---|
54 | reasons, Unicode 4.0 is used as the native character set for Qt.
|
---|
55 |
|
---|
56 |
|
---|
57 | \section1 Information about Unicode on the Web
|
---|
58 |
|
---|
59 | The \l{http://www.unicode.org/}{Unicode Consortium} has a number
|
---|
60 | of documents available, including
|
---|
61 |
|
---|
62 | \list
|
---|
63 |
|
---|
64 | \i \l{http://www.unicode.org/unicode/standard/principles.html}{A
|
---|
65 | technical introduction to Unicode}
|
---|
66 | \i \l{http://www.unicode.org/unicode/standard/standard.html}{The
|
---|
67 | home page for the standard}
|
---|
68 |
|
---|
69 | \endlist
|
---|
70 |
|
---|
71 |
|
---|
72 | \section1 The Standard
|
---|
73 |
|
---|
74 | The current version of the standard is 4.0.0.
|
---|
75 |
|
---|
76 | \list
|
---|
77 |
|
---|
78 | \i \link http://www.amazon.com/exec/obidos/ASIN/0321185781/trolltech/t
|
---|
79 | The Unicode Standard, version 4.0.\endlink See also
|
---|
80 | \link http://www.unicode.org/unicode/standard/versions/
|
---|
81 | its home page.\endlink
|
---|
82 | \i \link http://www.amazon.com/exec/obidos/ASIN/0201616335/trolltech/t
|
---|
83 | The Unicode Standard, version 3.2.\endlink
|
---|
84 | \i \link http://www.amazon.com/exec/obidos/ASIN/0201473459/trolltech/t
|
---|
85 | The Unicode Standard, version 2.0.\endlink See also the
|
---|
86 | \link http://www.unicode.org/unicode/reports/tr8.html 2.1
|
---|
87 | update\endlink and
|
---|
88 | \link http://www.unicode.org/unicode/standard/versions/enumeratedversions.html#Unicode 2.1.9 the 2.1.9 data files\endlink at www.unicode.org.
|
---|
89 |
|
---|
90 | \endlist
|
---|
91 |
|
---|
92 | \section1 Unicode in Qt
|
---|
93 |
|
---|
94 | In Qt, and in most applications that use Qt, most or all user-visible
|
---|
95 | strings are stored using Unicode. Qt provides:
|
---|
96 |
|
---|
97 | \list
|
---|
98 |
|
---|
99 | \i Translation to/from legacy encodings for file I/O: see
|
---|
100 | QTextCodec and QTextStream.
|
---|
101 | \i Translation from Input Methods and 8-bit keyboard input.
|
---|
102 | \i Translation to legacy character sets for on-screen display.
|
---|
103 | \i A string class, QString, that stores Unicode characters, with
|
---|
104 | support for migrating from C strings including fast (cached)
|
---|
105 | translation to and from US-ASCII, and all the usual string
|
---|
106 | operations.
|
---|
107 | \i Unicode-aware widgets where appropriate.
|
---|
108 | \i Unicode support detection on Windows, so that Qt provides Unicode
|
---|
109 | even on Windows platforms that do not support it natively.
|
---|
110 |
|
---|
111 | \endlist
|
---|
112 |
|
---|
113 | To fully benefit from Unicode, we recommend using QString for storing
|
---|
114 | all user-visible strings, and performing all text file I/O using
|
---|
115 | QTextStream. Use QKeyEvent::text() for keyboard input in any custom
|
---|
116 | widgets you write; it does not make much difference for slow typists
|
---|
117 | in Western Europe or North America, but for fast typists or people
|
---|
118 | using special input methods using text() is beneficial.
|
---|
119 |
|
---|
120 | All the function arguments in Qt that may be user-visible strings,
|
---|
121 | QLabel::setText() and a many others, take \c{const QString &}s.
|
---|
122 | QString provides implicit casting from \c{const char *}
|
---|
123 | so that things like
|
---|
124 |
|
---|
125 | \snippet doc/src/snippets/code/doc_src_unicode.qdoc 0
|
---|
126 |
|
---|
127 | will work. There is also a function, QObject::tr(), that provides
|
---|
128 | translation support, like this:
|
---|
129 |
|
---|
130 | \snippet doc/src/snippets/code/doc_src_unicode.qdoc 1
|
---|
131 |
|
---|
132 | QObject::tr() maps from \c{const char *} to a Unicode string, and
|
---|
133 | uses installable QTranslator objects to do the mapping.
|
---|
134 |
|
---|
135 | Qt provides a number of built-in QTextCodec classes, that is,
|
---|
136 | classes that know how to translate between Unicode and legacy
|
---|
137 | encodings to support programs that must talk to other programs or
|
---|
138 | read/write files in legacy file formats.
|
---|
139 |
|
---|
140 | By default, conversion to/from \c{const char *} uses a
|
---|
141 | locale-dependent codec. However, applications can easily find codecs
|
---|
142 | for other locales, and set any open file or network connection to use
|
---|
143 | a special codec. It is also possible to install new codecs, for
|
---|
144 | encodings that the built-in ones do not support. (At the time of
|
---|
145 | writing, Vietnamese/VISCII is one such example.)
|
---|
146 |
|
---|
147 | Since US-ASCII and ISO-8859-1 are so common, there are also especially
|
---|
148 | fast functions for mapping to and from them. For example, to open an
|
---|
149 | application's icon one might do this:
|
---|
150 |
|
---|
151 | \snippet doc/src/snippets/code/doc_src_unicode.qdoc 2
|
---|
152 |
|
---|
153 | or
|
---|
154 |
|
---|
155 | \snippet doc/src/snippets/code/doc_src_unicode.qdoc 3
|
---|
156 |
|
---|
157 | Regarding output, Qt will do a best-effort conversion from
|
---|
158 | Unicode to whatever encoding the system and fonts provide.
|
---|
159 | Depending on operating system, locale, font availability, and Qt's
|
---|
160 | support for the characters used, this conversion may be good or bad.
|
---|
161 | We will extend this in upcoming versions, with emphasis on the most
|
---|
162 | common locales first.
|
---|
163 |
|
---|
164 | \sa {Internationalization with Qt}
|
---|
165 | */
|
---|