Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
doc_src_qiterator.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
#
include
<
QList
>
4
#
include
<
QSet
>
5
6
void
example
()
7
{
8
{
9
//! [0]
10
QList<
float
> list;
11
//...
12
QListIterator<
float
> i(list);
13
while
(i.hasNext())
14
float
f = i.next();
15
//! [0]
16
}
17
18
QList<
float
> list;
19
20
{
21
//! [1]
22
QListIterator<
float
> i(list);
23
i.toBack();
24
while
(i.hasPrevious())
25
float
f = i.previous();
26
//! [1]
27
}
28
29
{
30
//! [6]
31
QSet<QString> set;
32
//...
33
QSetIterator<QString> i(set);
34
while
(i.hasNext())
35
QString f = i.next();
36
//! [6]
37
}
38
39
{
40
//! [8]
41
QList<
float
> list;
42
//...
43
QMutableListIterator<
float
> i(list);
44
while
(i.hasNext())
45
float
f = i.next();
46
//! [8]
47
}
48
49
{
50
//! [9]
51
QMutableListIterator<
float
> i(list);
52
i.toBack();
53
while
(i.hasPrevious())
54
float
f = i.previous();
55
//! [9]
56
}
57
58
{
59
QList<
int
> list = {1, 2, 3, 4, 5};
60
//! [10]
61
QMutableListIterator<
int
> i(list);
62
while
(i.hasNext()) {
63
int
val = i.next();
64
if
(val < 0) {
65
i.setValue(-val);
66
}
else
if
(val == 0) {
67
i.remove();
68
}
69
}
70
//! [10]
71
}
72
73
{
74
//! [17]
75
QSet<
float
> set;
76
//...
77
QMutableSetIterator<
float
> i(set);
78
while
(i.hasNext())
79
float
f = i.next();
80
//! [17]
81
}
82
83
{
84
QList<
int
> list = {1, 2, 3, 4, 5};
85
//! [19]
86
QMutableListIterator<
int
> i(list);
87
while
(i.hasNext()) {
88
int
val = i.next();
89
if
(val < -32768 || val > 32767)
90
i.remove();
91
}
92
//! [19]
93
}
94
95
{
96
QSet<
int
> set;
97
//! [22]
98
QMutableSetIterator<
int
> i(set);
99
while
(i.hasNext()) {
100
int
val = i.next();
101
if
(val < -32768 || val > 32767)
102
i.remove();
103
}
104
//! [22]
105
}
106
107
{
108
QList<
double
> list;
109
//! [23]
110
QMutableListIterator<
double
> i(list);
111
while
(i.hasNext()) {
112
double
val = i.next();
113
i.setValue(std::sqrt(val));
114
}
115
//! [23]
116
}
117
118
{
119
//! [25]
120
QList<
int
> list;
121
//...
122
QListIterator<
int
> i(list);
123
while
(i.hasNext())
124
int
val = i.next();
125
//! [25]
126
}
127
}
128
129
#
if
__has_include
(
<
QWidget
>
)
130
#
include
<
QWidget
>
131
void
example_widgets()
132
{
133
QMap<
int
, QWidget *> map;
134
{
135
//! [26]
136
QMap<
int
, QWidget *> map;
137
//...
138
QMapIterator<
int
, QWidget *> i(map);
139
while
(i.hasNext()) {
140
i.next();
141
qDebug() << i.key() <<
": "
<< i.value();
142
}
143
//! [26]
144
}
145
146
{
147
//! [27]
148
QMapIterator<
int
, QWidget *> i(map);
149
i.toBack();
150
while
(i.hasPrevious()) {
151
i.previous();
152
qDebug() << i.key() <<
": "
<< i.value();
153
}
154
//! [27]
155
}
156
157
QWidget *widget;
158
{
159
//! [28]
160
QMapIterator<
int
, QWidget *> i(map);
161
while
(i.findNext(widget)) {
162
qDebug() <<
"Found widget "
<< widget <<
" under key "
163
<< i.key();
164
}
165
//! [28]
166
}
167
168
{
169
//! [26multi]
170
QMultiMap<
int
, QWidget *> multimap;
171
//...
172
QMultiMapIterator<
int
, QWidget *> i(multimap);
173
while
(i.hasNext()) {
174
i.next();
175
qDebug() << i.key() <<
": "
<< i.value();
176
}
177
//! [26multi]
178
}
179
180
QMultiMap<
int
, QWidget *> multimap;
181
{
182
//! [27multi]
183
QMultiMapIterator<
int
, QWidget *> i(multimap);
184
i.toBack();
185
while
(i.hasPrevious()) {
186
i.previous();
187
qDebug() << i.key() <<
": "
<< i.value();
188
}
189
//! [27multi]
190
}
191
192
{
193
//! [28multi]
194
QMultiMapIterator<
int
, QWidget *> i(multimap);
195
while
(i.findNext(widget)) {
196
qDebug() <<
"Found widget "
<< widget <<
" under key "
197
<< i.key();
198
}
199
//! [28multi]
200
}
201
202
{
203
//! [29]
204
QHash<
int
, QWidget *> hash;
205
//...
206
QHashIterator<
int
, QWidget *> i(hash);
207
while
(i.hasNext()) {
208
i.next();
209
qDebug() << i.key() <<
": "
<< i.value();
210
}
211
//! [29]
212
}
213
214
QHash<
int
, QWidget *> hash;
215
{
216
//! [31]
217
QHashIterator<
int
, QWidget *> i(hash);
218
while
(i.findNext(widget)) {
219
qDebug() <<
"Found widget "
<< widget <<
" under key "
220
<< i.key();
221
}
222
//! [31]
223
}
224
225
{
226
//! [32]
227
QMap<
int
, QWidget *> map;
228
//...
229
QMutableMapIterator<
int
, QWidget *> i(map);
230
while
(i.hasNext()) {
231
i.next();
232
qDebug() << i.key() <<
": "
<< i.value();
233
}
234
//! [32]
235
}
236
237
{
238
//! [33]
239
QMutableMapIterator<
int
, QWidget *> i(map);
240
i.toBack();
241
while
(i.hasPrevious()) {
242
i.previous();
243
qDebug() << i.key() <<
": "
<< i.value();
244
}
245
//! [33]
246
}
247
248
{
249
//! [34]
250
QMutableMapIterator<
int
, QWidget *> i(map);
251
while
(i.findNext(widget)) {
252
qDebug() <<
"Found widget "
<< widget <<
" under key "
253
<< i.key();
254
}
255
//! [34]
256
}
257
258
{
259
QMap<QString, QString> map;
260
//! [35]
261
QMutableMapIterator<QString, QString> i(map);
262
while
(i.hasNext()) {
263
i.next();
264
if
(i.key() == i.value())
265
i.remove();
266
}
267
//! [35]
268
}
269
270
{
271
//! [32multi]
272
QMultiMap<
int
, QWidget *> multimap;
273
//...
274
QMutableMultiMapIterator<
int
, QWidget *> i(multimap);
275
while
(i.hasNext()) {
276
i.next();
277
qDebug() << i.key() <<
": "
<< i.value();
278
}
279
//! [32multi]
280
}
281
282
{
283
//! [33multi]
284
QMutableMultiMapIterator<
int
, QWidget *> i(multimap);
285
i.toBack();
286
while
(i.hasPrevious()) {
287
i.previous();
288
qDebug() << i.key() <<
": "
<< i.value();
289
}
290
//! [33multi]
291
}
292
293
{
294
//! [34multi]
295
QMutableMultiMapIterator<
int
, QWidget *> i(multimap);
296
while
(i.findNext(widget)) {
297
qDebug() <<
"Found widget "
<< widget <<
" under key "
298
<< i.key();
299
}
300
//! [34multi]
301
}
302
303
{
304
QMultiMap<QString, QString> multimap;
305
//! [35multi]
306
QMutableMultiMapIterator<QString, QString> i(multimap);
307
while
(i.hasNext()) {
308
i.next();
309
if
(i.key() == i.value())
310
i.remove();
311
}
312
//! [35multi]
313
}
314
315
{
316
//! [36]
317
QHash<
int
, QWidget *> hash;
318
//...
319
QMutableHashIterator<
int
, QWidget *> i(hash);
320
while
(i.hasNext()) {
321
i.next();
322
qDebug() << i.key() <<
": "
<< i.value();
323
}
324
//! [36]
325
}
326
327
{
328
//! [38]
329
QMutableHashIterator<
int
, QWidget *> i(hash);
330
while
(i.findNext(widget)) {
331
qDebug() <<
"Found widget "
<< widget <<
" under key "
332
<< i.key();
333
}
334
//! [38]
335
}
336
337
{
338
QHash<QString, QString> hash;
339
//! [39]
340
QMutableHashIterator<QString, QString> i(hash);
341
while
(i.hasNext()) {
342
i.next();
343
if
(i.key() == i.value())
344
i.remove();
345
}
346
//! [39]
347
}
348
}
349
#
endif
example
void example()
[5]
Definition
doc_src_groups.cpp:7
__has_include
#define __has_include(x)
Definition
qcompilerdetection.h:459
qtbase
src
corelib
doc
snippets
code
doc_src_qiterator.cpp
Generated on
for Qt by
1.18.0