~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qlist-iterator.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/corelib/tools/qlistdata.cpp -->
 
6
<head>
 
7
    <title>Qt 4.0: QList::iterator Class Reference</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<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">QList::iterator Class Reference</h1>
 
21
<p>The QList::iterator class provides an STL-style non-const iterator for <a href="qlist.html">QList</a> and <a href="qqueue.html">QQueue</a>. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;QList&gt;</pre><p>Part of the <a href="qtcore.html">QtCore</a> module.</p>
 
23
<ul>
 
24
<li><a href="qlist-iterator-members.html">List of all members, including inherited members</a></li>
 
25
</ul>
 
26
<a name="public-functions"></a>
 
27
<h3>Public Functions</h3>
 
28
<ul>
 
29
<li><div class="fn"/><b><a href="qlist-iterator.html#iterator">iterator</a></b> ()</li>
 
30
<li><div class="fn"/><b><a href="qlist-iterator.html#iterator-3">iterator</a></b> ( const iterator &amp; <i>other</i> )</li>
 
31
<li><div class="fn"/>bool <b><a href="qlist-iterator.html#operator-not-eq">operator!=</a></b> ( const iterator &amp; <i>other</i> ) const</li>
 
32
<li><div class="fn"/>bool <b><a href="qlist-iterator.html#operator-not-eq-2">operator!=</a></b> ( const const_iterator &amp; <i>other</i> ) const</li>
 
33
<li><div class="fn"/>T &amp; <b><a href="qlist-iterator.html#operator-2a">operator*</a></b> () const</li>
 
34
<li><div class="fn"/>iterator <b><a href="qlist-iterator.html#operator-2b">operator+</a></b> ( int <i>j</i> ) const</li>
 
35
<li><div class="fn"/>iterator &amp; <b><a href="qlist-iterator.html#operator-2b-2b">operator++</a></b> ()</li>
 
36
<li><div class="fn"/>iterator <b><a href="qlist-iterator.html#operator-2b-2b-2">operator++</a></b> ( int )</li>
 
37
<li><div class="fn"/>iterator &amp; <b><a href="qlist-iterator.html#operator-2b-eq">operator+=</a></b> ( int <i>j</i> )</li>
 
38
<li><div class="fn"/>iterator <b><a href="qlist-iterator.html#operator-">operator-</a></b> ( int <i>j</i> ) const</li>
 
39
<li><div class="fn"/>int <b><a href="qlist-iterator.html#operator--2">operator-</a></b> ( iterator <i>other</i> ) const</li>
 
40
<li><div class="fn"/>iterator &amp; <b><a href="qlist-iterator.html#operator--">operator--</a></b> ()</li>
 
41
<li><div class="fn"/>iterator <b><a href="qlist-iterator.html#operator---2">operator--</a></b> ( int )</li>
 
42
<li><div class="fn"/>iterator &amp; <b><a href="qlist-iterator.html#operator--eq">operator-=</a></b> ( int <i>j</i> )</li>
 
43
<li><div class="fn"/>T * <b><a href="qlist-iterator.html#operator--gt">operator-&gt;</a></b> () const</li>
 
44
<li><div class="fn"/>bool <b><a href="qlist-iterator.html#operator-lt">operator&lt;</a></b> ( const iterator &amp; <i>other</i> ) const</li>
 
45
<li><div class="fn"/>bool <b><a href="qlist-iterator.html#operator-lt-2">operator&lt;</a></b> ( const const_iterator &amp; <i>other</i> ) const</li>
 
46
<li><div class="fn"/>bool <b><a href="qlist-iterator.html#operator-lt-eq">operator&lt;=</a></b> ( const iterator &amp; <i>other</i> ) const</li>
 
47
<li><div class="fn"/>bool <b><a href="qlist-iterator.html#operator-lt-eq-2">operator&lt;=</a></b> ( const const_iterator &amp; <i>other</i> ) const</li>
 
48
<li><div class="fn"/>bool <b><a href="qlist-iterator.html#operator-eq-eq">operator==</a></b> ( const iterator &amp; <i>other</i> ) const</li>
 
49
<li><div class="fn"/>bool <b><a href="qlist-iterator.html#operator-eq-eq-2">operator==</a></b> ( const const_iterator &amp; <i>other</i> ) const</li>
 
50
<li><div class="fn"/>bool <b><a href="qlist-iterator.html#operator-gt">operator&gt;</a></b> ( const iterator &amp; <i>other</i> ) const</li>
 
51
<li><div class="fn"/>bool <b><a href="qlist-iterator.html#operator-gt-2">operator&gt;</a></b> ( const const_iterator &amp; <i>other</i> ) const</li>
 
52
<li><div class="fn"/>bool <b><a href="qlist-iterator.html#operator-gt-eq">operator&gt;=</a></b> ( const iterator &amp; <i>other</i> ) const</li>
 
53
<li><div class="fn"/>bool <b><a href="qlist-iterator.html#operator-gt-eq-2">operator&gt;=</a></b> ( const const_iterator &amp; <i>other</i> ) const</li>
 
54
<li><div class="fn"/>T &amp; <b><a href="qlist-iterator.html#operator-5b-5d">operator[]</a></b> ( int <i>j</i> ) const</li>
 
55
</ul>
 
56
<a name="details"></a>
 
57
<hr />
 
58
<h2>Detailed Description</h2>
 
59
<p>The QList::iterator class provides an STL-style non-const iterator for <a href="qlist.html">QList</a> and <a href="qqueue.html">QQueue</a>.</p>
 
60
<p><a href="qlist.html">QList</a> features both <a href="containers.html#stl-style-iterators">STL-style iterators</a> and <a href="containers.html#java-style-iterators">Java-style iterators</a>. The STL-style iterators are more low-level and more cumbersome to use; on the other hand, they are slightly faster and, for developers who already know STL, have the advantage of familiarity.</p>
 
61
<p><a href="qlist.html">QList</a>&lt;T&gt;::iterator allows you to iterate over a <a href="qlist.html">QList</a>&lt;T&gt; (or <a href="qqueue.html">QQueue</a>&lt;T&gt;) and to modify the list item associated with the iterator. If you want to iterate over a const <a href="qlist.html">QList</a>, use <a href="qlist-const-iterator.html">QList::const_iterator</a> instead. It is generally good practice to use <a href="qlist-const-iterator.html">QList::const_iterator</a> on a non-const <a href="qlist.html">QList</a> as well, unless you need to change the <a href="qlist.html">QList</a> through the iterator. Const iterators are slightly faster, and can improve code readability.</p>
 
62
<p>The default QList::iterator constructor creates an uninitialized iterator. You must initialize it using a <a href="qlist.html">QList</a> function like <a href="qlist.html#begin">QList::begin</a>(), <a href="qlist.html#end">QList::end</a>(), or <a href="qlist.html#insert">QList::insert</a>() before you can start iterating. Here's a typical loop that prints all the items stored in a list:</p>
 
63
<pre>&nbsp;   QList&lt;QString&gt; list;
 
64
    list.append(&quot;January&quot;);
 
65
    list.append(&quot;February&quot;);
 
66
    ...
 
67
    list.append(&quot;December&quot;);
 
68
 
 
69
    QList&lt;QString&gt;::iterator i;
 
70
    for (i = list.begin(); i != list.end(); ++i)
 
71
        cout &lt;&lt; *i &lt;&lt; endl;</pre>
 
72
<p>Let's see a few examples of things we can do with a QList::iterator that we cannot do with a <a href="qlist-const-iterator.html">QList::const_iterator</a>. Here's an example that increments every value stored in a <a href="qlist.html">QList</a>&lt;int&gt; by 2:</p>
 
73
<pre>&nbsp;   QList&lt;int&gt;::iterator i;
 
74
    for (i = list.begin(); i != list.end(); ++i)
 
75
        *i += 2;</pre>
 
76
<p>Most <a href="qlist.html">QList</a> functions accept an integer index rather than an iterator. For that reason, iterators are rarely useful in connection with <a href="qlist.html">QList</a>. One place where STL-style iterators do make sense is as arguments to <a href="qtalgorithms.html">generic algorithms</a>.</p>
 
77
<p>For example, here's how to delete all the widgets stored in a <a href="qlist.html">QList</a>&lt;<a href="qwidget.html">QWidget</a> *&gt;:</p>
 
78
<pre>&nbsp;   QList&lt;QWidget *&gt; list;
 
79
    ...
 
80
    qDeleteAll(list.begin(), list.end());</pre>
 
81
<p>Multiple iterators can be used on the same list. However, be aware that any non-const function call performed on the <a href="qlist.html">QList</a> will render all existing iterators undefined. If you need to keep iterators over a long period of time, we recommend that you use <a href="qlinkedlist.html">QLinkedList</a> rather than <a href="qlist.html">QList</a>.</p>
 
82
<p>See also <a href="qlist-const-iterator.html">QList::const_iterator</a> and <a href="qmutablelistiterator.html">QMutableListIterator</a>.</p>
 
83
<hr />
 
84
<h2>Member Function Documentation</h2>
 
85
<h3 class="fn"><a name="iterator"></a>iterator::iterator ()</h3>
 
86
<p>Constructs an uninitialized iterator.</p>
 
87
<p>Functions like operator*() and operator++() should not be called on an uninitialized iterartor. Use operator=() to assign a value to it before using it.</p>
 
88
<p>See also <a href="qlist.html#begin">QList::begin</a>() and <a href="qlist.html#end">QList::end</a>().</p>
 
89
<h3 class="fn"><a name="iterator-3"></a>iterator::iterator ( const iterator &amp; <i>other</i> )</h3>
 
90
<p>Constructs a copy of <i>other</i>.</p>
 
91
<h3 class="fn"><a name="operator-not-eq"></a>bool iterator::operator!= ( const iterator &amp; <i>other</i> ) const</h3>
 
92
<p>Returns true if <i>other</i> points to a different item than this iterator; otherwise returns false.</p>
 
93
<p>See also <a href="qlist-iterator.html#operator-eq-eq">operator==</a>().</p>
 
94
<h3 class="fn"><a name="operator-not-eq-2"></a>bool iterator::operator!= ( const <a href="qlist-const-iterator.html">const_iterator</a> &amp; <i>other</i> ) const</h3>
 
95
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
96
<p>Returns true if <i>other</i> points to a different item than this iterator; otherwise returns false.</p>
 
97
<p>See also <a href="qlist-iterator.html#operator-eq-eq">operator==</a>().</p>
 
98
<h3 class="fn"><a name="operator-2a"></a>T &amp; iterator::operator* () const</h3>
 
99
<p>Returns a modifiable reference to the current item.</p>
 
100
<p>You can change the value of an item by using operator*() on the left side of an assignment, for example:</p>
 
101
<pre>&nbsp;   if (*it == &quot;Hello&quot;)
 
102
        *it = &quot;Bonjour&quot;;</pre>
 
103
<p>See also <a href="qlist-iterator.html#operator--gt">operator-&gt;</a>().</p>
 
104
<h3 class="fn"><a name="operator-2b"></a>iterator iterator::operator+ ( int <i>j</i> ) const</h3>
 
105
<p>Returns an iterator to the item at <i>j</i> positions forward from this iterator. (If <i>j</i> is negative, the iterator goes backward.)</p>
 
106
<p>See also <a href="qlist-iterator.html#operator-">operator-</a>() and <a href="qlist-iterator.html#operator-2b-eq">operator+=</a>().</p>
 
107
<h3 class="fn"><a name="operator-2b-2b"></a>iterator &amp; iterator::operator++ ()</h3>
 
108
<p>The prefix ++ operator (<tt>++it</tt>) advances the iterator to the next item in the list and returns an iterator to the new current item.</p>
 
109
<p>Calling this function on <a href="qlist.html#end">QList::end</a>() leads to undefined results.</p>
 
110
<p>See also <a href="qlist-iterator.html#operator--">operator--</a>().</p>
 
111
<h3 class="fn"><a name="operator-2b-2b-2"></a>iterator iterator::operator++ ( int )</h3>
 
112
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
113
<p>The postfix ++ operator (<tt>it++</tt>) advances the iterator to the next item in the list and returns an iterator to the previously current item.</p>
 
114
<h3 class="fn"><a name="operator-2b-eq"></a>iterator &amp; iterator::operator+= ( int <i>j</i> )</h3>
 
115
<p>Advances the iterator by <i>j</i> items. (If <i>j</i> is negative, the iterator goes backward.)</p>
 
116
<p>See also <a href="qlist-iterator.html#operator--eq">operator-=</a>() and <a href="qlist-iterator.html#operator-2b">operator+</a>().</p>
 
117
<h3 class="fn"><a name="operator-"></a>iterator iterator::operator- ( int <i>j</i> ) const</h3>
 
118
<p>Returns an iterator to the item at <i>j</i> positions backward from this iterator. (If <i>j</i> is negative, the iterator goes forward.)</p>
 
119
<p>See also <a href="qlist-iterator.html#operator-2b">operator+</a>() and <a href="qlist-iterator.html#operator--eq">operator-=</a>().</p>
 
120
<h3 class="fn"><a name="operator--2"></a>int iterator::operator- ( iterator <i>other</i> ) const</h3>
 
121
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
122
<p>Returns the number of items between the item pointed to by <i>other</i> and the item pointed to by this iterator.</p>
 
123
<h3 class="fn"><a name="operator--"></a>iterator &amp; iterator::operator-- ()</h3>
 
124
<p>The prefix -- operator (<tt>--it</tt>) makes the preceding item current and returns an iterator to the new current item.</p>
 
125
<p>Calling this function on <a href="qlist.html#begin">QList::begin</a>() leads to undefined results.</p>
 
126
<p>See also <a href="qlist-iterator.html#operator-2b-2b">operator++</a>().</p>
 
127
<h3 class="fn"><a name="operator---2"></a>iterator iterator::operator-- ( int )</h3>
 
128
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
129
<p>The postfix -- operator (<tt>it--</tt>) makes the preceding item current and returns an iterator to the previously current item.</p>
 
130
<h3 class="fn"><a name="operator--eq"></a>iterator &amp; iterator::operator-= ( int <i>j</i> )</h3>
 
131
<p>Makes the iterator go back by <i>j</i> items. (If <i>j</i> is negative, the iterator goes forward.)</p>
 
132
<p>See also <a href="qlist-iterator.html#operator-2b-eq">operator+=</a>() and <a href="qlist-iterator.html#operator-">operator-</a>().</p>
 
133
<h3 class="fn"><a name="operator--gt"></a>T * iterator::operator-&gt; () const</h3>
 
134
<p>Returns a pointer to the current item.</p>
 
135
<p>See also <a href="qlist-iterator.html#operator-2a">operator*</a>().</p>
 
136
<h3 class="fn"><a name="operator-lt"></a>bool iterator::operator&lt; ( const iterator &amp; <i>other</i> ) const</h3>
 
137
<p>Returns true if the item pointed to by this iterator is less than the item pointed to by the <i>other</i> iterator.</p>
 
138
<h3 class="fn"><a name="operator-lt-2"></a>bool iterator::operator&lt; ( const <a href="qlist-const-iterator.html">const_iterator</a> &amp; <i>other</i> ) const</h3>
 
139
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
140
<p>Returns true if the item pointed to by this iterator is less than the item pointed to by the <i>other</i> iterator.</p>
 
141
<h3 class="fn"><a name="operator-lt-eq"></a>bool iterator::operator&lt;= ( const iterator &amp; <i>other</i> ) const</h3>
 
142
<p>Returns true if the item pointed to by this iterator is less than or equal to the item pointed to by the <i>other</i> iterator.</p>
 
143
<h3 class="fn"><a name="operator-lt-eq-2"></a>bool iterator::operator&lt;= ( const <a href="qlist-const-iterator.html">const_iterator</a> &amp; <i>other</i> ) const</h3>
 
144
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
145
<p>Returns true if the item pointed to by this iterator is less than or equal to the item pointed to by the <i>other</i> iterator.</p>
 
146
<h3 class="fn"><a name="operator-eq-eq"></a>bool iterator::operator== ( const iterator &amp; <i>other</i> ) const</h3>
 
147
<p>Returns true if <i>other</i> points to the same item as this iterator; otherwise returns false.</p>
 
148
<p>See also <a href="qlist-iterator.html#operator-not-eq">operator!=</a>().</p>
 
149
<h3 class="fn"><a name="operator-eq-eq-2"></a>bool iterator::operator== ( const <a href="qlist-const-iterator.html">const_iterator</a> &amp; <i>other</i> ) const</h3>
 
150
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
151
<p>Returns true if <i>other</i> points to the same item as this iterator; otherwise returns false.</p>
 
152
<p>See also <a href="qlist-iterator.html#operator-not-eq">operator!=</a>().</p>
 
153
<h3 class="fn"><a name="operator-gt"></a>bool iterator::operator&gt; ( const iterator &amp; <i>other</i> ) const</h3>
 
154
<p>Returns true if the item pointed to by this iterator is greater than the item pointed to by the <i>other</i> iterator.</p>
 
155
<h3 class="fn"><a name="operator-gt-2"></a>bool iterator::operator&gt; ( const <a href="qlist-const-iterator.html">const_iterator</a> &amp; <i>other</i> ) const</h3>
 
156
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
157
<p>Returns true if the item pointed to by this iterator is greater than the item pointed to by the <i>other</i> iterator.</p>
 
158
<h3 class="fn"><a name="operator-gt-eq"></a>bool iterator::operator&gt;= ( const iterator &amp; <i>other</i> ) const</h3>
 
159
<p>Returns true if the item pointed to by this iterator is greater than or equal to the item pointed to by the <i>other</i> iterator.</p>
 
160
<h3 class="fn"><a name="operator-gt-eq-2"></a>bool iterator::operator&gt;= ( const <a href="qlist-const-iterator.html">const_iterator</a> &amp; <i>other</i> ) const</h3>
 
161
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
162
<p>Returns true if the item pointed to by this iterator is greater than or equal to the item pointed to by the <i>other</i> iterator.</p>
 
163
<h3 class="fn"><a name="operator-5b-5d"></a>T &amp; iterator::operator[] ( int <i>j</i> ) const</h3>
 
164
<p>Returns a modifiable reference to the item at position *this + <i>j</i>.</p>
 
165
<p>This function is provided to make <a href="qlist.html">QList</a> iterators behave like C++ pointers.</p>
 
166
<p>See also <a href="qlist-iterator.html#operator-2b">operator+</a>().</p>
 
167
<p /><address><hr /><div align="center">
 
168
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
169
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
170
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
171
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
172
</tr></table></div></address></body>
 
173
</html>