3
3
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
4
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
<!-- /tmp/qt-4.1.4-harald-1150713676011/qt-x11-opensource-src-4.1.4/doc/src/qiterator.qdoc -->
6
<!-- /tmp/qt-4.1.4-harald-1150713676011/qt-x11-opensource-src-4.1.4/doc/src/qiterator.qdoc -->
5
<!-- /tmp/qt-4.2.0-qt-1159540607313/qt-x11-opensource-src-4.2.0/doc/src/qiterator.qdoc -->
8
<title>Qt 4.1: QMutableLinkedListIterator Class Reference</title>
9
<style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
10
a:link { color: #004faf; text-decoration: none }
11
a:visited { color: #672967; text-decoration: none }
12
td.postheader { font-family: sans-serif }
13
tr.address { font-family: sans-serif }
14
body { background: #ffffff; color: black; }</style>
7
<title>Qt 4.2: QMutableLinkedListIterator Class Reference</title>
8
<link href="classic.css" rel="stylesheet" type="text/css" />
17
11
<table border="0" cellpadding="0" cellspacing="0" width="100%">
19
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
13
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
20
14
<td width="1"> </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> · <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a> · <a href="functions.html"><font color="#004faf">Functions</font></a></td>
21
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QMutableLinkedListIterator Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1>
15
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QMutableLinkedListIterator Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1>
22
16
<p>The QMutableLinkedListIterator class provides a Java-style non-const iterator for <a href="qlinkedlist.html">QLinkedList</a>. <a href="#details">More...</a></p>
23
<pre>#include <QMutableLinkedListIterator></pre><ul>
17
<pre> #include <QMutableLinkedListIterator></pre><ul>
24
18
<li><a href="qmutablelinkedlistiterator-members.html">List of all members, including inherited members</a></li>
26
20
<a name="public-functions"></a>
52
46
<p><a href="qlinkedlist.html">QLinkedList</a> has both <a href="containers.html#java-style-iterators">Java-style iterators</a> and <a href="containers.html#stl-style-iterators">STL-style iterators</a>. The Java-style iterators are more high-level and easier to use than the STL-style iterators; on the other hand, they are slightly less efficient.</p>
53
47
<p>QMutableLinkedListIterator<T> allows you to iterate over a <a href="qlinkedlist.html">QLinkedList</a><T> and modify the list. If you don't want to modify the list (or have a const <a href="qlinkedlist.html">QLinkedList</a>), use the slightly faster <a href="qlinkedlistiterator.html">QLinkedListIterator</a><T> instead.</p>
54
48
<p>The QMutableLinkedListIterator constructor takes a <a href="qlinkedlist.html">QLinkedList</a> as argument. After construction, the iterator is located at the very beginning of the list (before the first item). Here's how to iterate over all the elements sequentially:</p>
55
<pre> QLinkedList<float> list;
57
QMutableLinkedListIterator<float> i(list);
59
qDebug() << i.next();</pre>
49
<pre> QLinkedList<float> list;
51
QMutableLinkedListIterator<float> i(list);
53
qDebug() << i.next();</pre>
60
54
<p>The <a href="qmutablelinkedlistiterator.html#next">next</a>() function returns the next item in the list and advances the iterator. Unlike STL-style iterators, Java-style iterators point <i>between</i> items rather than directly <i>at</i> items. The first call to <a href="qmutablelinkedlistiterator.html#next">next</a>() advances the iterator to the position between the first and second item, and returns the first item; the second call to <a href="qmutablelinkedlistiterator.html#next">next</a>() advances the iterator to the position between the second and third item, returning the second item; and so on.</p>
61
55
<p align="center"><img src="images/javaiterators1.png" /></p><p>Here's how to iterate over the elements in reverse order:</p>
62
<pre> QMutableLinkedListIterator<float> i(list);
64
while (i.hasPrevious())
65
qDebug() << i.previous();</pre>
56
<pre> QMutableLinkedListIterator<float> i(list);
58
while (i.hasPrevious())
59
qDebug() << i.previous();</pre>
66
60
<p>If you want to find all occurrences of a particular value, use <a href="qmutablelinkedlistiterator.html#findNext">findNext</a>() or <a href="qmutablelinkedlistiterator.html#findPrevious">findPrevious</a>() in a loop.</p>
67
61
<p>If you want to remove items as you iterate over the list, use <a href="qmutablelinkedlistiterator.html#remove">remove</a>(). If you want to modify the value of an item, use <a href="qmutablelinkedlistiterator.html#setValue">setValue</a>(). If you want to insert a new item in the list, use <a href="qmutablelinkedlistiterator.html#insert">insert</a>().</p>
69
<pre> QMutableLinkedListIterator<int> i(list);
74
} else if (val == 0) {
63
<pre> QMutableLinkedListIterator<int> i(list);
68
} else if (val == 0) {
78
72
<p>The example traverses a list, replacing negative numbers with their absolute values, and eliminating zeroes.</p>
79
73
<p>Only one mutable iterator can be active on a given list at any time. Furthermore, no changes should be done directly to the list while the iterator is active (as opposed to through the iterator), since this could invalidate the iterator and lead to undefined behavior.</p>
80
74
<p>See also <a href="qlinkedlistiterator.html">QLinkedListIterator</a> and <a href="qlinkedlist-iterator.html">QLinkedList::iterator</a>.</p>
122
116
<h3 class="fn"><a name="remove"></a>void QMutableLinkedListIterator::remove ()</h3>
123
117
<p>Removes the last item that was jumped over using one of the traversal functions (<a href="qmutablelinkedlistiterator.html#next">next</a>(), <a href="qmutablelinkedlistiterator.html#previous">previous</a>(), <a href="qmutablelinkedlistiterator.html#findNext">findNext</a>(), <a href="qmutablelinkedlistiterator.html#findPrevious">findPrevious</a>()).</p>
125
<pre> QMutableLinkedListIterator<int> i(list);
126
while (i.hasNext()) {
128
if (val < -32768 || val > 32767)
119
<pre> QMutableLinkedListIterator<int> i(list);
120
while (i.hasNext()) {
122
if (val < -32768 || val > 32767)
131
125
<p>See also <a href="qmutablelinkedlistiterator.html#insert">insert</a>() and <a href="qmutablelinkedlistiterator.html#setValue">setValue</a>().</p>
132
126
<h3 class="fn"><a name="setValue"></a>void QMutableLinkedListIterator::setValue ( const T & <i>value</i> ) const</h3>
133
127
<p>Replaces the value of the last item that was jumped over using one of the traversal functions with <i>value</i>.</p>
134
128
<p>The traversal functions are <a href="qmutablelinkedlistiterator.html#next">next</a>(), <a href="qmutablelinkedlistiterator.html#previous">previous</a>(), <a href="qmutablelinkedlistiterator.html#findNext">findNext</a>(), and <a href="qmutablelinkedlistiterator.html#findPrevious">findPrevious</a>().</p>
136
<pre> QMutableLinkedListIterator<double> i(list);
137
while (i.hasNext()) {
138
double val = i.next();
139
i.setValue(sqrt(val));
130
<pre> QMutableLinkedListIterator<double> i(list);
131
while (i.hasNext()) {
132
double val = i.next();
133
i.setValue(sqrt(val));
141
135
<p>See also <a href="qmutablelinkedlistiterator.html#value">value</a>(), <a href="qmutablelinkedlistiterator.html#remove">remove</a>(), and <a href="qmutablelinkedlistiterator.html#insert">insert</a>().</p>
142
136
<h3 class="fn"><a name="toBack"></a>void QMutableLinkedListIterator::toBack ()</h3>
143
137
<p>Moves the iterator to the back of the container (after the last item).</p>
159
153
<table width="100%" cellspacing="0" border="0"><tr class="address">
160
154
<td width="30%">Copyright © 2006 <a href="trolltech.html">Trolltech</a></td>
161
155
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
162
<td width="30%" align="right"><div align="right">Qt 4.1.4</div></td>
156
<td width="30%" align="right"><div align="right">Qt 4.2.0</div></td>
163
157
</tr></table></div></address></body>