doc/src/snippets/code/doc_src_qt4-tulip.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 foreach (variable, container)
       
    44     statement;
       
    45 //! [0]
       
    46 
       
    47 
       
    48 //! [1]
       
    49 QList<QString> list;
       
    50 ...
       
    51 foreach (QString str, list)
       
    52     cout << str.ascii() << endl;
       
    53 //! [1]
       
    54 
       
    55 
       
    56 //! [2]
       
    57 QString str;
       
    58 foreach (str, list)
       
    59     cout << str.ascii() << endl;
       
    60 //! [2]
       
    61 
       
    62 
       
    63 //! [3]
       
    64 // forward                                  // backward
       
    65 QList<QString> list;                        QList<QString> list;
       
    66 ...                                         ...
       
    67 QListIterator<QString> i(list);             QListIterator<QString> i(list);        
       
    68 while (i.hasNext())                         i.toBack();                            
       
    69     cout << i.next().ascii() << endl;       while (i.hasPrev())                    
       
    70                                                 cout << i.prev().ascii() << endl;
       
    71 //! [3]
       
    72 
       
    73 
       
    74 //! [4]
       
    75 // forward                                  // backward
       
    76 QMutableListIterator<int> i(list);          QMutableListIterator<int> i(list);  
       
    77 while (i.hasNext())                         i.toBack();                         
       
    78     if (i.next() > 128)                     while (i.hasPrev())                 
       
    79         i.setValue(128);                        if (i.prev() > 128)             
       
    80                                                     i.setValue(128);           
       
    81 //! [4]
       
    82 
       
    83 
       
    84 //! [5]
       
    85 // forward                                  // backward
       
    86 QMutableListIterator<int> i(list);          QMutableListIterator<int> i(list);                 
       
    87 while (i.hasNext())                         i.toBack();                         
       
    88     if (i.next() % 2 != 0)                  while (i.hasPrev())                        
       
    89         i.remove();                             if (i.prev() % 2 != 0)          
       
    90                                                     i.remove();                 
       
    91 //! [5]
       
    92 
       
    93 
       
    94 //! [6]
       
    95 // STL-style                                // Java-style
       
    96 QMap<int, QWidget *>::const_iterator i;     QMapIterator<int, QWidget *> i(map);
       
    97 for (i = map.begin(); i != map.end(); ++i)  while (i.findNext(widget))
       
    98     if (i.value() == widget)                    cout << "Found widget " << widget
       
    99         cout << "Found widget " << widget            << " under key "
       
   100              << " under key "                        << i.key() << endl;
       
   101              << i.key() << endl;
       
   102 //! [6]
       
   103 
       
   104 
       
   105 //! [7]
       
   106 // STL-style                                // Java-style
       
   107 QList<int>::iterator i = list.begin();      QMutableListIterator<int> i(list);
       
   108 while (i != list.end()) {                   while (i.hasNext()) {
       
   109     if (*i == 0) {                              int val = i.next();
       
   110         i = list.erase(i);                      if (val < 0)
       
   111     } else {                                        i.setValue(-val);
       
   112         if (*i < 0)                             else if (val == 0)
       
   113             *i = -*i;                               i.remove();
       
   114         ++i;                                }
       
   115     }
       
   116 }
       
   117 //! [7]
       
   118 
       
   119 
       
   120 //! [8]
       
   121 QList<double> list;
       
   122 ...
       
   123 for (int i = 0; i < list.size(); ++i) {
       
   124     if (list[i] < 0.0)
       
   125         list[i] = 0.0;
       
   126 }
       
   127 //! [8]
       
   128 
       
   129 
       
   130 //! [9]
       
   131 QMap<QString, int> map;
       
   132 ...
       
   133 map.value("TIMEOUT", 30);  // returns 30 if "TIMEOUT" isn't in the map
       
   134 //! [9]
       
   135 
       
   136 
       
   137 //! [10]
       
   138 QMultiMap<QString, int> map;
       
   139 ...
       
   140 QList<int> values = map.values("TIMEOUT");
       
   141 //! [10]