source: trunk/doc/src/snippets/code/doc_src_qt4-tulip.qdoc@ 5

Last change on this file since 5 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 3.1 KB
Line 
1//! [0]
2foreach (variable, container)
3 statement;
4//! [0]
5
6
7//! [1]
8QList<QString> list;
9...
10foreach (QString str, list)
11 cout << str.ascii() << endl;
12//! [1]
13
14
15//! [2]
16QString str;
17foreach (str, list)
18 cout << str.ascii() << endl;
19//! [2]
20
21
22//! [3]
23// forward // backward
24QList<QString> list; QList<QString> list;
25... ...
26QListIterator<QString> i(list); QListIterator<QString> i(list);
27while (i.hasNext()) i.toBack();
28 cout << i.next().ascii() << endl; while (i.hasPrev())
29 cout << i.prev().ascii() << endl;
30//! [3]
31
32
33//! [4]
34// forward // backward
35QMutableListIterator<int> i(list); QMutableListIterator<int> i(list);
36while (i.hasNext()) i.toBack();
37 if (i.next() > 128) while (i.hasPrev())
38 i.setValue(128); if (i.prev() > 128)
39 i.setValue(128);
40//! [4]
41
42
43//! [5]
44// forward // backward
45QMutableListIterator<int> i(list); QMutableListIterator<int> i(list);
46while (i.hasNext()) i.toBack();
47 if (i.next() % 2 != 0) while (i.hasPrev())
48 i.remove(); if (i.prev() % 2 != 0)
49 i.remove();
50//! [5]
51
52
53//! [6]
54// STL-style // Java-style
55QMap<int, QWidget *>::const_iterator i; QMapIterator<int, QWidget *> i(map);
56for (i = map.begin(); i != map.end(); ++i) while (i.findNext(widget))
57 if (i.value() == widget) cout << "Found widget " << widget
58 cout << "Found widget " << widget << " under key "
59 << " under key " << i.key() << endl;
60 << i.key() << endl;
61//! [6]
62
63
64//! [7]
65// STL-style // Java-style
66QList<int>::iterator i = list.begin(); QMutableListIterator<int> i(list);
67while (i != list.end()) { while (i.hasNext()) {
68 if (*i == 0) { int val = i.next();
69 i = list.erase(i); if (val < 0)
70 } else { i.setValue(-val);
71 if (*i < 0) else if (val == 0)
72 *i = -*i; i.remove();
73 ++i; }
74 }
75}
76//! [7]
77
78
79//! [8]
80QList<double> list;
81...
82for (int i = 0; i < list.size(); ++i) {
83 if (list[i] < 0.0)
84 list[i] = 0.0;
85}
86//! [8]
87
88
89//! [9]
90QMap<QString, int> map;
91...
92map.value("TIMEOUT", 30); // returns 30 if "TIMEOUT" isn't in the map
93//! [9]
94
95
96//! [10]
97QMultiMap<QString, int> map;
98...
99QList<int> values = map.values("TIMEOUT");
100//! [10]
Note: See TracBrowser for help on using the repository browser.