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_qset.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
4
#
include
<
QtCore
>
5
#
include
<
iostream
>
6
7
using
namespace
std
;
8
void
snippets_0_3
()
9
{
10
//! [0]
11
QSet<QString> set;
12
//! [0]
13
14
15
//! [1]
16
set.insert(
"one"
);
17
set.insert(
"three"
);
18
set.insert(
"seven"
);
19
//! [1]
20
21
22
//! [2]
23
set <<
"twelve"
<<
"fifteen"
<<
"nineteen"
;
24
//! [2]
25
26
27
//! [3]
28
if
(!set.contains(
"ninety-nine"
))
29
{
/*...*/
}
30
//! [3]
31
}
32
33
#
if
__has_include
(
<
QWidget
>
)
34
35
#
include
<
QWidget
>
36
37
void
example_widgets()
38
{
39
QSet<QWidget *> set;
40
//! [4]
41
QSetIterator<QWidget *> i(set);
42
while
(i.hasNext()) {
43
QWidget *w = i.next();
44
qDebug() << w;
45
}
46
//! [4]
47
}
48
#
endif
49
50
void
snippets_5_12
()
51
{
52
QSet<QString> set;
53
54
//! [5]
55
for
(
auto
i = set.cbegin(), end = set.cend(); i != end; ++i)
56
qDebug() << *i;
57
//! [5]
58
59
{
60
//! [6]
61
QSet<QString> set;
62
//...
63
for
(
const
auto
&value : set)
64
qDebug() << value;
65
//! [6]
66
}
67
68
{
69
QString values[3];
70
//! [7]
71
QSet<QString> set;
72
set.reserve(20000);
73
for
(
int
i = 0; i < 20000; ++i)
74
set.insert(values[i]);
75
//! [7]
76
}
77
78
{
79
//! [8]
80
QSet<QString> set = {
"January"
,
"February"
,
/*...*/
"December"
};
81
82
// i is a QSet<QString>::iterator
83
for
(
auto
i = set.begin(), end = set.end(); i != end; ++i)
84
qDebug() << *i;
85
//! [8]
86
}
87
88
{
89
//! [9]
90
QSet<QString> set = {
"January"
,
"February"
,
/*...*/
"December"
};
91
92
auto
i = set.begin();
93
while
(i != set.end()) {
94
if
((*i).startsWith(
'J'
)) {
95
i = set.erase(i);
96
}
else
{
97
++i;
98
}
99
}
100
//! [9]
101
}
102
103
{
104
//! [10]
105
QSet<QString> set;
106
//...
107
const
auto
predicate = [](
const
QString &s) {
return
s.compare(
"Jeanette"
, Qt::CaseInsensitive) == 0; };
108
QSet<QString>::iterator it = std::find_if(set.begin(), set.end(), predicate);
109
if
(it != set.end())
110
cout <<
"Found Jeanette"
<< endl;
111
//! [10]
112
}
113
114
{
115
//! [11]
116
QSet<QString> set = {
"January"
,
"February"
,
/*...*/
"December"
};
117
118
// i is QSet<QString>::const_iterator
119
for
(
auto
i = set.cbegin(), end = set.cend(); i != end; ++i)
120
qDebug() << *i;
121
//! [11]
122
}
123
124
{
125
//! [12]
126
QSet<QString> set;
127
//...
128
const
auto
predicate = [](
const
QString &s) {
return
s.compare(
"Jeanette"
, Qt::CaseInsensitive) == 0; };
129
QSet<QString>::const_iterator it = std::find_if(set.cbegin(), set.cend(), predicate);
130
if
(it != set.constEnd())
131
cout <<
"Found Jeanette"
<< endl;
132
//! [12]
133
}
134
}
snippets_5_12
void snippets_5_12()
Definition
doc_src_qset.cpp:50
snippets_0_3
void snippets_0_3()
Definition
doc_src_qset.cpp:8
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
__has_include
#define __has_include(x)
Definition
qcompilerdetection.h:459
qtbase
src
corelib
doc
snippets
code
doc_src_qset.cpp
Generated on
for Qt by
1.18.0