source: trunk/doc/src/frameworks-technologies/unicode.qdoc@ 564

Last change on this file since 564 was 561, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.1 sources.

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