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