|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the documentation of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 //! [0] |
|
43 class Employee |
|
44 { |
|
45 public: |
|
46 Employee() {} |
|
47 Employee(const Employee &other); |
|
48 |
|
49 Employee &operator=(const Employee &other); |
|
50 |
|
51 private: |
|
52 QString myName; |
|
53 QDate myDateOfBirth; |
|
54 }; |
|
55 //! [0] |
|
56 |
|
57 |
|
58 //! [1] |
|
59 QList<QString> list; |
|
60 list << "A" << "B" << "C" << "D"; |
|
61 |
|
62 QListIterator<QString> i(list); |
|
63 while (i.hasNext()) |
|
64 qDebug() << i.next(); |
|
65 //! [1] |
|
66 |
|
67 |
|
68 //! [2] |
|
69 QListIterator<QString> i(list); |
|
70 i.toBack(); |
|
71 while (i.hasPrevious()) |
|
72 qDebug() << i.previous(); |
|
73 //! [2] |
|
74 |
|
75 |
|
76 //! [3] |
|
77 QMutableListIterator<int> i(list); |
|
78 while (i.hasNext()) { |
|
79 if (i.next() % 2 != 0) |
|
80 i.remove(); |
|
81 } |
|
82 //! [3] |
|
83 |
|
84 |
|
85 //! [4] |
|
86 QMutableListIterator<int> i(list); |
|
87 i.toBack(); |
|
88 while (i.hasPrevious()) { |
|
89 if (i.previous() % 2 != 0) |
|
90 i.remove(); |
|
91 } |
|
92 //! [4] |
|
93 |
|
94 |
|
95 //! [5] |
|
96 QMutableListIterator<int> i(list); |
|
97 while (i.hasNext()) { |
|
98 if (i.next() > 128) |
|
99 i.setValue(128); |
|
100 } |
|
101 //! [5] |
|
102 |
|
103 |
|
104 //! [6] |
|
105 QMutableListIterator<int> i(list); |
|
106 while (i.hasNext()) |
|
107 i.next() *= 2; |
|
108 //! [6] |
|
109 |
|
110 |
|
111 //! [7] |
|
112 QMap<QString, QString> map; |
|
113 map.insert("Paris", "France"); |
|
114 map.insert("Guatemala City", "Guatemala"); |
|
115 map.insert("Mexico City", "Mexico"); |
|
116 map.insert("Moscow", "Russia"); |
|
117 ... |
|
118 |
|
119 QMutableMapIterator<QString, QString> i(map); |
|
120 while (i.hasNext()) { |
|
121 if (i.next().key().endsWith("City")) |
|
122 i.remove(); |
|
123 } |
|
124 //! [7] |
|
125 |
|
126 |
|
127 //! [8] |
|
128 QMap<int, QWidget *> map; |
|
129 QHash<int, QWidget *> hash; |
|
130 |
|
131 QMapIterator<int, QWidget *> i(map); |
|
132 while (i.hasNext()) { |
|
133 i.next(); |
|
134 hash.insert(i.key(), i.value()); |
|
135 } |
|
136 //! [8] |
|
137 |
|
138 |
|
139 //! [9] |
|
140 QMutableMapIterator<int, QWidget *> i(map); |
|
141 while (i.findNext(widget)) |
|
142 i.remove(); |
|
143 //! [9] |
|
144 |
|
145 |
|
146 //! [10] |
|
147 QList<QString> list; |
|
148 list << "A" << "B" << "C" << "D"; |
|
149 |
|
150 QList<QString>::iterator i; |
|
151 for (i = list.begin(); i != list.end(); ++i) |
|
152 *i = (*i).toLower(); |
|
153 //! [10] |
|
154 |
|
155 |
|
156 //! [11] |
|
157 QList<QString> list; |
|
158 list << "A" << "B" << "C" << "D"; |
|
159 |
|
160 QList<QString>::iterator i = list.end(); |
|
161 while (i != list.begin()) { |
|
162 --i; |
|
163 *i = (*i).toLower(); |
|
164 } |
|
165 //! [11] |
|
166 |
|
167 |
|
168 //! [12] |
|
169 QList<QString>::const_iterator i; |
|
170 for (i = list.constBegin(); i != list.constEnd(); ++i) |
|
171 qDebug() << *i; |
|
172 //! [12] |
|
173 |
|
174 |
|
175 //! [13] |
|
176 QMap<int, int> map; |
|
177 ... |
|
178 QMap<int, int>::const_iterator i; |
|
179 for (i = map.constBegin(); i != map.constEnd(); ++i) |
|
180 qDebug() << i.key() << ":" << i.value(); |
|
181 //! [13] |
|
182 |
|
183 |
|
184 //! [14] |
|
185 // RIGHT |
|
186 const QList<int> sizes = splitter->sizes(); |
|
187 QList<int>::const_iterator i; |
|
188 for (i = sizes.begin(); i != sizes.end(); ++i) |
|
189 ... |
|
190 |
|
191 // WRONG |
|
192 QList<int>::const_iterator i; |
|
193 for (i = splitter->sizes().begin(); |
|
194 i != splitter->sizes().end(); ++i) |
|
195 ... |
|
196 //! [14] |
|
197 |
|
198 |
|
199 //! [15] |
|
200 QLinkedList<QString> list; |
|
201 ... |
|
202 QString str; |
|
203 foreach (str, list) |
|
204 qDebug() << str; |
|
205 //! [15] |
|
206 |
|
207 |
|
208 //! [16] |
|
209 QLinkedList<QString> list; |
|
210 ... |
|
211 QLinkedListIterator<QString> i(list); |
|
212 while (i.hasNext()) |
|
213 qDebug() << i.next(); |
|
214 //! [16] |
|
215 |
|
216 |
|
217 //! [17] |
|
218 QLinkedList<QString> list; |
|
219 ... |
|
220 foreach (QString str, list) |
|
221 qDebug() << str; |
|
222 //! [17] |
|
223 |
|
224 |
|
225 //! [18] |
|
226 QLinkedList<QString> list; |
|
227 ... |
|
228 foreach (QString str, list) { |
|
229 if (str.isEmpty()) |
|
230 break; |
|
231 qDebug() << str; |
|
232 } |
|
233 //! [18] |
|
234 |
|
235 |
|
236 //! [19] |
|
237 QMap<QString, int> map; |
|
238 ... |
|
239 foreach (QString str, map.keys()) |
|
240 qDebug() << str << ":" << map.value(str); |
|
241 //! [19] |
|
242 |
|
243 |
|
244 //! [20] |
|
245 QMultiMap<QString, int> map; |
|
246 ... |
|
247 foreach (QString str, map.uniqueKeys()) { |
|
248 foreach (int i, map.values(str)) |
|
249 qDebug() << str << ":" << i; |
|
250 } |
|
251 //! [20] |
|
252 |
|
253 |
|
254 //! [21] |
|
255 forever { |
|
256 ... |
|
257 } |
|
258 //! [21] |
|
259 |
|
260 |
|
261 //! [22] |
|
262 CONFIG += no_keywords |
|
263 //! [22] |
|
264 |
|
265 |
|
266 //! [23] |
|
267 QString onlyLetters(const QString &in) |
|
268 { |
|
269 QString out; |
|
270 for (int j = 0; j < in.size(); ++j) { |
|
271 if (in[j].isLetter()) |
|
272 out += in[j]; |
|
273 } |
|
274 return out; |
|
275 } |
|
276 //! [23] |