source: trunk/doc/src/snippets/code/doc_src_qset.qdoc@ 788

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

trunk: Merged in qt 4.6.2 sources.

File size: 3.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 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//! [0]
43QSet<QString> set;
44//! [0]
45
46
47//! [1]
48set.insert("one");
49set.insert("three");
50set.insert("seven");
51//! [1]
52
53
54//! [2]
55set << "twelve" << "fifteen" << "nineteen";
56//! [2]
57
58
59//! [3]
60if (!set.contains("ninety-nine"))
61 ...
62//! [3]
63
64
65//! [4]
66QSetIterator<QWidget *> i(set);
67while (i.hasNext())
68 qDebug() << i.next();
69//! [4]
70
71
72//! [5]
73QSet<QWidget *>::const_iterator i = set.constBegin();
74while (i != set.constEnd()) {
75 qDebug() << *i;
76 ++i;
77}
78//! [5]
79
80
81//! [6]
82QSet<QString> set;
83...
84foreach (QString value, set)
85 qDebug() << value;
86//! [6]
87
88
89//! [7]
90QSet<QString> set;
91set.reserve(20000);
92for (int i = 0; i < 20000; ++i)
93 set.insert(values[i]);
94//! [7]
95
96
97//! [8]
98QSet<QString> set;
99set << "January" << "February" << ... << "December";
100
101QSet<QString>::iterator i;
102for (i = set.begin(); i != set.end(); ++i)
103 qDebug() << *i;
104//! [8]
105
106
107//! [9]
108QSet<QString> set;
109set << "January" << "February" << ... << "December";
110
111QSet<QString>::iterator i = set.begin();
112while (i != set.end()) {
113 if ((*i).startsWith('J')) {
114 i = set.erase(i);
115 } else {
116 ++i;
117 }
118}
119//! [9]
120
121
122//! [10]
123QSet<QString> set;
124...
125QSet<QString>::iterator it = qFind(set.begin(), set.end(), "Jeanette");
126if (it != set.end())
127 cout << "Found Jeanette" << endl;
128//! [10]
129
130
131//! [11]
132QSet<QString> set;
133set << "January" << "February" << ... << "December";
134
135QSet<QString>::const_iterator i;
136for (i = set.begin(); i != set.end(); ++i)
137 qDebug() << *i;
138//! [11]
139
140
141//! [12]
142QSet<QString> set;
143...
144QSet<QString>::iterator it = qFind(set.begin(), set.end(), "Jeanette");
145if (it != set.constEnd())
146 cout << "Found Jeanette" << endl;
147//! [12]
148
149
150//! [13]
151QSet<QString> set;
152set << "red" << "green" << "blue" << ... << "black";
153
154QList<QString> list = set.toList();
155qSort(list);
156//! [13]
157
158
159//! [14]
160QStringList list;
161list << "Julia" << "Mike" << "Mike" << "Julia" << "Julia";
162
163QSet<QString> set = QSet<QString>::fromList(list);
164set.contains("Julia"); // returns true
165set.contains("Mike"); // returns true
166set.size(); // returns 2
167//! [14]
Note: See TracBrowser for help on using the repository browser.