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

« back to all changes in this revision

Viewing changes to doc/html/qlist.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 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 Class Reference</h1>
 
21
<p>The QList class is a template class that provides lists. <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
<p>Inherited by <a href="qitemselection.html">QItemSelection</a>, <a href="qqueue.html">QQueue</a>, and <a href="qstringlist.html">QStringList</a>.</p>
 
24
<p><b>Note:</b> All the functions in this class are <a href="threads.html#reentrant">reentrant</a>.</p>
 
25
<ul>
 
26
<li><a href="qlist-members.html">List of all members, including inherited members</a></li>
 
27
<li><a href="qlist-qt3.html">Qt 3 support members</a></li>
 
28
</ul>
 
29
<a name="public-types"></a>
 
30
<h3>Public Types</h3>
 
31
<ul>
 
32
<li><div class="fn"/>class <b><a href="qlist-const-iterator.html">const_iterator</a></b></li>
 
33
<li><div class="fn"/>class <b><a href="qlist-iterator.html">iterator</a></b></li>
 
34
<li><div class="fn"/>typedef <b><a href="qlist.html#ConstIterator-typedef">ConstIterator</a></b></li>
 
35
<li><div class="fn"/>typedef <b><a href="qlist.html#Iterator-typedef">Iterator</a></b></li>
 
36
<li><div class="fn"/>typedef <b><a href="qlist.html#const_pointer-typedef">const_pointer</a></b></li>
 
37
<li><div class="fn"/>typedef <b><a href="qlist.html#const_reference-typedef">const_reference</a></b></li>
 
38
<li><div class="fn"/>typedef <b><a href="qlist.html#pointer-typedef">pointer</a></b></li>
 
39
<li><div class="fn"/>typedef <b><a href="qlist.html#reference-typedef">reference</a></b></li>
 
40
<li><div class="fn"/>typedef <b><a href="qlist.html#size_type-typedef">size_type</a></b></li>
 
41
<li><div class="fn"/>typedef <b><a href="qlist.html#value_type-typedef">value_type</a></b></li>
 
42
</ul>
 
43
<a name="public-functions"></a>
 
44
<h3>Public Functions</h3>
 
45
<ul>
 
46
<li><div class="fn"/><b><a href="qlist.html#QList">QList</a></b> ()</li>
 
47
<li><div class="fn"/><b><a href="qlist.html#QList-2">QList</a></b> ( const QList &amp; <i>other</i> )</li>
 
48
<li><div class="fn"/><b><a href="qlist.html#dtor.QList">~QList</a></b> ()</li>
 
49
<li><div class="fn"/>void <b><a href="qlist.html#append">append</a></b> ( const T &amp; <i>value</i> )</li>
 
50
<li><div class="fn"/>const T &amp; <b><a href="qlist.html#at">at</a></b> ( int <i>i</i> ) const</li>
 
51
<li><div class="fn"/>T &amp; <b><a href="qlist.html#back">back</a></b> ()</li>
 
52
<li><div class="fn"/>const T &amp; <b><a href="qlist.html#back-2">back</a></b> () const</li>
 
53
<li><div class="fn"/>iterator <b><a href="qlist.html#begin">begin</a></b> ()</li>
 
54
<li><div class="fn"/>const_iterator <b><a href="qlist.html#begin-2">begin</a></b> () const</li>
 
55
<li><div class="fn"/>void <b><a href="qlist.html#clear">clear</a></b> ()</li>
 
56
<li><div class="fn"/>const_iterator <b><a href="qlist.html#constBegin">constBegin</a></b> () const</li>
 
57
<li><div class="fn"/>const_iterator <b><a href="qlist.html#constEnd">constEnd</a></b> () const</li>
 
58
<li><div class="fn"/>bool <b><a href="qlist.html#contains">contains</a></b> ( const T &amp; <i>value</i> ) const</li>
 
59
<li><div class="fn"/>int <b><a href="qlist.html#count">count</a></b> ( const T &amp; <i>value</i> ) const</li>
 
60
<li><div class="fn"/>int <b><a href="qlist.html#count-2">count</a></b> () const</li>
 
61
<li><div class="fn"/>bool <b><a href="qlist.html#empty">empty</a></b> () const</li>
 
62
<li><div class="fn"/>iterator <b><a href="qlist.html#end">end</a></b> ()</li>
 
63
<li><div class="fn"/>const_iterator <b><a href="qlist.html#end-2">end</a></b> () const</li>
 
64
<li><div class="fn"/>iterator <b><a href="qlist.html#erase">erase</a></b> ( iterator <i>pos</i> )</li>
 
65
<li><div class="fn"/>iterator <b><a href="qlist.html#erase-2">erase</a></b> ( iterator <i>begin</i>, iterator <i>end</i> )</li>
 
66
<li><div class="fn"/>T &amp; <b><a href="qlist.html#first">first</a></b> ()</li>
 
67
<li><div class="fn"/>const T &amp; <b><a href="qlist.html#first-2">first</a></b> () const</li>
 
68
<li><div class="fn"/>T &amp; <b><a href="qlist.html#front">front</a></b> ()</li>
 
69
<li><div class="fn"/>const T &amp; <b><a href="qlist.html#front-2">front</a></b> () const</li>
 
70
<li><div class="fn"/>int <b><a href="qlist.html#indexOf">indexOf</a></b> ( const T &amp; <i>value</i>, int <i>from</i> = 0 ) const</li>
 
71
<li><div class="fn"/>void <b><a href="qlist.html#insert">insert</a></b> ( int <i>i</i>, const T &amp; <i>value</i> )</li>
 
72
<li><div class="fn"/>iterator <b><a href="qlist.html#insert-2">insert</a></b> ( iterator <i>before</i>, const T &amp; <i>value</i> )</li>
 
73
<li><div class="fn"/>bool <b><a href="qlist.html#isEmpty">isEmpty</a></b> () const</li>
 
74
<li><div class="fn"/>T &amp; <b><a href="qlist.html#last">last</a></b> ()</li>
 
75
<li><div class="fn"/>const T &amp; <b><a href="qlist.html#last-2">last</a></b> () const</li>
 
76
<li><div class="fn"/>int <b><a href="qlist.html#lastIndexOf">lastIndexOf</a></b> ( const T &amp; <i>value</i>, int <i>from</i> = -1 ) const</li>
 
77
<li><div class="fn"/>QList&lt;T&gt; <b><a href="qlist.html#mid">mid</a></b> ( int <i>pos</i>, int <i>length</i> = -1 ) const</li>
 
78
<li><div class="fn"/>void <b><a href="qlist.html#move">move</a></b> ( int <i>from</i>, int <i>to</i> )</li>
 
79
<li><div class="fn"/>void <b><a href="qlist.html#pop_back">pop_back</a></b> ()</li>
 
80
<li><div class="fn"/>void <b><a href="qlist.html#pop_front">pop_front</a></b> ()</li>
 
81
<li><div class="fn"/>void <b><a href="qlist.html#prepend">prepend</a></b> ( const T &amp; <i>value</i> )</li>
 
82
<li><div class="fn"/>void <b><a href="qlist.html#push_back">push_back</a></b> ( const T &amp; <i>value</i> )</li>
 
83
<li><div class="fn"/>void <b><a href="qlist.html#push_front">push_front</a></b> ( const T &amp; <i>value</i> )</li>
 
84
<li><div class="fn"/>int <b><a href="qlist.html#removeAll">removeAll</a></b> ( const T &amp; <i>value</i> )</li>
 
85
<li><div class="fn"/>void <b><a href="qlist.html#removeAt">removeAt</a></b> ( int <i>i</i> )</li>
 
86
<li><div class="fn"/>void <b><a href="qlist.html#removeFirst">removeFirst</a></b> ()</li>
 
87
<li><div class="fn"/>void <b><a href="qlist.html#removeLast">removeLast</a></b> ()</li>
 
88
<li><div class="fn"/>void <b><a href="qlist.html#replace">replace</a></b> ( int <i>i</i>, const T &amp; <i>value</i> )</li>
 
89
<li><div class="fn"/>int <b><a href="qlist.html#size">size</a></b> () const</li>
 
90
<li><div class="fn"/>void <b><a href="qlist.html#swap">swap</a></b> ( int <i>i</i>, int <i>j</i> )</li>
 
91
<li><div class="fn"/>T <b><a href="qlist.html#takeAt">takeAt</a></b> ( int <i>i</i> )</li>
 
92
<li><div class="fn"/>T <b><a href="qlist.html#takeFirst">takeFirst</a></b> ()</li>
 
93
<li><div class="fn"/>T <b><a href="qlist.html#takeLast">takeLast</a></b> ()</li>
 
94
<li><div class="fn"/>QSet&lt;T&gt; <b><a href="qlist.html#toSet">toSet</a></b> () const</li>
 
95
<li><div class="fn"/>std::list&lt;T&gt; <b><a href="qlist.html#toStdList">toStdList</a></b> () const</li>
 
96
<li><div class="fn"/>QVector&lt;T&gt; <b><a href="qlist.html#toVector">toVector</a></b> () const</li>
 
97
<li><div class="fn"/>T <b><a href="qlist.html#value">value</a></b> ( int <i>i</i> ) const</li>
 
98
<li><div class="fn"/>T <b><a href="qlist.html#value-2">value</a></b> ( int <i>i</i>, const T &amp; <i>defaultValue</i> ) const</li>
 
99
<li><div class="fn"/>bool <b><a href="qlist.html#operator-not-eq">operator!=</a></b> ( const QList &amp; <i>other</i> ) const</li>
 
100
<li><div class="fn"/>QList <b><a href="qlist.html#operator-2b">operator+</a></b> ( const QList &amp; <i>other</i> ) const</li>
 
101
<li><div class="fn"/>QList &amp; <b><a href="qlist.html#operator-2b-eq">operator+=</a></b> ( const QList &amp; <i>other</i> )</li>
 
102
<li><div class="fn"/>QList &amp; <b><a href="qlist.html#operator-2b-eq-2">operator+=</a></b> ( const T &amp; <i>value</i> )</li>
 
103
<li><div class="fn"/>QList &amp; <b><a href="qlist.html#operator-lt-lt">operator&lt;&lt;</a></b> ( const QList &amp; <i>other</i> )</li>
 
104
<li><div class="fn"/>QList &amp; <b><a href="qlist.html#operator-lt-lt-2">operator&lt;&lt;</a></b> ( const T &amp; <i>value</i> )</li>
 
105
<li><div class="fn"/>QList &amp; <b><a href="qlist.html#operator-eq">operator=</a></b> ( const QList &amp; <i>other</i> )</li>
 
106
<li><div class="fn"/>bool <b><a href="qlist.html#operator-eq-eq">operator==</a></b> ( const QList &amp; <i>other</i> ) const</li>
 
107
<li><div class="fn"/>T &amp; <b><a href="qlist.html#operator-5b-5d">operator[]</a></b> ( int <i>i</i> )</li>
 
108
<li><div class="fn"/>const T &amp; <b><a href="qlist.html#operator-5b-5d-2">operator[]</a></b> ( int <i>i</i> ) const</li>
 
109
</ul>
 
110
<a name="static-public-members"></a>
 
111
<h3>Static Public Members</h3>
 
112
<ul>
 
113
<li><div class="fn"/>QList&lt;T&gt; <b><a href="qlist.html#fromSet">fromSet</a></b> ( const QSet&lt;T&gt; &amp; <i>set</i> )</li>
 
114
<li><div class="fn"/>QList&lt;T&gt; <b><a href="qlist.html#fromStdList">fromStdList</a></b> ( const std::list&lt;T&gt; &amp; <i>list</i> )</li>
 
115
<li><div class="fn"/>QList&lt;T&gt; <b><a href="qlist.html#fromVector">fromVector</a></b> ( const QVector&lt;T&gt; &amp; <i>vector</i> )</li>
 
116
</ul>
 
117
<a name="related-non-members"></a>
 
118
<h3>Related Non-Members</h3>
 
119
<ul>
 
120
<li><div class="fn"/>QDataStream &amp; <b><a href="qlist.html#operator-lt-lt-5">operator&lt;&lt;</a></b> ( QDataStream &amp; <i>out</i>, const QList&lt;T&gt; &amp; <i>list</i> )</li>
 
121
<li><div class="fn"/>QDataStream &amp; <b><a href="qlist.html#operator-gt-gt-5">operator&gt;&gt;</a></b> ( QDataStream &amp; <i>in</i>, QList&lt;T&gt; &amp; <i>list</i> )</li>
 
122
</ul>
 
123
<a name="details"></a>
 
124
<hr />
 
125
<h2>Detailed Description</h2>
 
126
<p>The QList class is a template class that provides lists.</p>
 
127
<p>QList&lt;T&gt; is one of Qt's generic <a href="containers.html#container-classes">container classes</a>. It stores a list of values and provides fast index-based access as well as fast insertions and removals.</p>
 
128
<p>QList&lt;T&gt;, <a href="qlinkedlist.html">QLinkedList</a>&lt;T&gt;, and <a href="qvector.html">QVector</a>&lt;T&gt; provide similar functionality. Here's an overview:</p>
 
129
<ul>
 
130
<li>For most purposes, QList is the right class to use. Its index-based API is more convenient than <a href="qlinkedlist.html">QLinkedList</a>'s iterator-based API, and it is usually faster than <a href="qvector.html">QVector</a> because of the way it stores its items in memory. It also expands to less code in your executable.</li>
 
131
<li>If you need a real linked list, with guarantees of <a href="containers.html#constant-time">constant time</a> insertions in the middle of the list and iterators to items rather than indexes, use <a href="qlinkedlist.html">QLinkedList</a>.</li>
 
132
<li>If you want the items to occupy adjacent memory positions, use <a href="qvector.html">QVector</a>.</li>
 
133
</ul>
 
134
<p>Internally, QList&lt;T&gt; is represented as an array of pointers to items. (Exceptionally, if T is a pointer type, a basic type of the size of a pointer, or one of Qt's <a href="shclass.html#shared-classes">shared classes</a>, QList&lt;T&gt; stores the item directly in the pointer.) For lists under a thousand items, this representation allows for very fast insertions in the middle, in addition to instantaneous index-based access. Furthermore, operations like <a href="qlist.html#prepend">prepend</a>() and <a href="qlist.html#append">append</a>() are very fast, because QList preallocates memory on both sides of its internal array.</p>
 
135
<p>Here's an example of a QList that stores integers and a QList that stores <a href="qdate.html">QDate</a> values:</p>
 
136
<pre>&nbsp;   QList&lt;int&gt; integerList;
 
137
    QList&lt;QDate&gt; dateList;</pre>
 
138
<p>Qt includes a <a href="qstringlist.html">QStringList</a> class that inherits QList&lt;<a href="qstring.html">QString</a>&gt; and adds a few convenience functions, such as <a href="qstringlist.html#join">QStringList::join</a>() and <a href="qlist-qt3.html#find">QStringList::find</a>(). (<a href="qstring.html#split">QString::split</a>() creates QStringLists from strings.)</p>
 
139
<p>QList stores a list of items. The default constructor creates an empty list. To insert items into the list, you can use operator&lt;&lt;():</p>
 
140
<pre>&nbsp;   QList&lt;QString&gt; list;
 
141
    list &lt;&lt; &quot;one&quot; &lt;&lt; &quot;two&quot; &lt;&lt; &quot;three&quot;;
 
142
    // list: [&quot;one&quot;, &quot;two&quot;, &quot;three&quot;]</pre>
 
143
<p>QList provides these basic functions to add, move, and remove items: <a href="qlist.html#insert">insert</a>(), <a href="qlist.html#replace">replace</a>(), <a href="qlist.html#removeAt">removeAt</a>(), <a href="qlist.html#move">move</a>(), and <a href="qlist.html#swap">swap</a>(). In addition, it provides the following convenience functions: <a href="qlist.html#append">append</a>(), <a href="qlist.html#prepend">prepend</a>(), <a href="qlist.html#removeFirst">removeFirst</a>(), and <a href="qlist.html#removeLast">removeLast</a>().</p>
 
144
<p>QList uses 0-based indexes, just like C++ arrays. To access the item at a particular index position, you can use operator[](). On non-const lists, operator[]() returns a reference to the item and can be used on the left side of an assignment:</p>
 
145
<pre>&nbsp;   if (list[0] == &quot;Bob&quot;)
 
146
        list[0] = &quot;Robert&quot;;</pre>
 
147
<p>Because QList is implemented as an array of pointers, this operation is very fast (<a href="containers.html#constant-time">constant time</a>). For read-only access, an alternative syntax is to use <a href="qlist.html#at">at</a>():</p>
 
148
<pre>&nbsp;   for (int i = 0; i &lt; list.size(); ++i) {
 
149
        if (list.at(i) == &quot;Jane&quot;)
 
150
            cout &lt;&lt; &quot;Found Jane at position &quot; &lt;&lt; i &lt;&lt; endl;
 
151
    }</pre>
 
152
<p><a href="qlist.html#at">at</a>() can be faster than operator[](), because it never causes a <a href="shclass.html#deep-copy">deep copy</a> to occur.</p>
 
153
<p>A common requirement is to remove an item from a list and do something with it. For this, QList provides <a href="qlist.html#takeAt">takeAt</a>(), <a href="qlist.html#takeFirst">takeFirst</a>(), and <a href="qlist.html#takeLast">takeLast</a>(). Here's a loop that removes the items from a list one at a time and calls <tt>delete</tt> on them:</p>
 
154
<pre>&nbsp;   QList&lt;QWidget *&gt; list;
 
155
    ...
 
156
    while (!list.isEmpty())
 
157
        delete list.takeFirst();</pre>
 
158
<p>Inserting and removing items at either ends of the list is very fast (<a href="containers.html#constant-time">constant time</a> in most cases), because QList preallocates extra space on both sides of its internal buffer to allow for fast growth at both ends of the list.</p>
 
159
<p>If you want to find all occurrences of a particular value in a list, use <a href="qlist.html#indexOf">indexOf</a>() or <a href="qlist.html#lastIndexOf">lastIndexOf</a>(). The former searches forward starting from a given index position, the latter searches backward. Both return the index of a matching item if they find it; otherwise, they return -1. For example:</p>
 
160
<pre>&nbsp;   int i = list.indexOf(&quot;Jane&quot;);
 
161
    if (i != -1)
 
162
        cout &lt;&lt; &quot;First occurrence of Jane is at position &quot; &lt;&lt; i &lt;&lt; endl;</pre>
 
163
<p>If you simply want to check whether a list contains a particular value, use <a href="qlist.html#contains">contains</a>(). If you want to find out how many times a particular value occurs in the list, use <a href="qlist.html#count">count</a>(). If you want to replace all occurrences of a particular value with another, use <a href="qlist.html#replace">replace</a>().</p>
 
164
<p>QList's value type must be an <a href="containers.html#assignable-data-types">assignable data type</a>. This covers most data types that are commonly used, but the compiler won't let you, for example, store a <a href="qwidget.html">QWidget</a> as a value; instead, store a <a href="qwidget.html">QWidget</a> *. A few functions have additional requirements; for example, <a href="qlist.html#indexOf">indexOf</a>() and <a href="qlist.html#lastIndexOf">lastIndexOf</a>() expect the value type to support <tt>operator==()</tt>. These requirements are documented on a per-function basis.</p>
 
165
<p>Like the other container classes, QList provides <a href="containers.html#java-style-iterators">Java-style iterators</a> (<a href="qlistiterator.html">QListIterator</a> and <a href="qmutablelistiterator.html">QMutableListIterator</a>) and <a href="containers.html#stl-style-iterators">STL-style iterators</a> (<a href="qlist-const-iterator.html">QList::const_iterator</a> and <a href="qlist-iterator.html">QList::iterator</a>). In practice, these are rarely used, because you can use indexes into the QList. QList is implemented in such a way that direct index-based access is just as fast as using iterators.</p>
 
166
<p>QList does <i>not</i> support inserting, prepending, appending or replacing with references to its own values. Doing so will cause your application to abort with an error message.</p>
 
167
<p>See also <a href="qlistiterator.html">QListIterator</a>, <a href="qmutablelistiterator.html">QMutableListIterator</a>, <a href="qlinkedlist.html">QLinkedList</a>, and <a href="qvector.html">QVector</a>.</p>
 
168
<hr />
 
169
<h2>Member Type Documentation</h2>
 
170
<h3 class="fn"><a name="ConstIterator-typedef"></a>typedef QList::ConstIterator</h3>
 
171
<p>Qt-style synonym for <a href="qlist-const-iterator.html">QList::const_iterator</a>.</p>
 
172
<h3 class="fn"><a name="Iterator-typedef"></a>typedef QList::Iterator</h3>
 
173
<p>Qt-style synonym for <a href="qlist-iterator.html">QList::iterator</a>.</p>
 
174
<h3 class="fn"><a name="const_pointer-typedef"></a>typedef QList::const_pointer</h3>
 
175
<p>Typedef for const T *. Provided for STL compatibility.</p>
 
176
<h3 class="fn"><a name="const_reference-typedef"></a>typedef QList::const_reference</h3>
 
177
<p>Typedef for const T &amp;. Provided for STL compatibility.</p>
 
178
<h3 class="fn"><a name="pointer-typedef"></a>typedef QList::pointer</h3>
 
179
<p>Typedef for T *. Provided for STL compatibility.</p>
 
180
<h3 class="fn"><a name="reference-typedef"></a>typedef QList::reference</h3>
 
181
<p>Typedef for T &amp;. Provided for STL compatibility.</p>
 
182
<h3 class="fn"><a name="size_type-typedef"></a>typedef QList::size_type</h3>
 
183
<p>Typedef for int. Provided for STL compatibility.</p>
 
184
<h3 class="fn"><a name="value_type-typedef"></a>typedef QList::value_type</h3>
 
185
<p>Typedef for T. Provided for STL compatibility.</p>
 
186
<hr />
 
187
<h2>Member Function Documentation</h2>
 
188
<h3 class="fn"><a name="QList"></a>QList::QList ()</h3>
 
189
<p>Constructs an empty list.</p>
 
190
<h3 class="fn"><a name="QList-2"></a>QList::QList ( const QList &amp; <i>other</i> )</h3>
 
191
<p>Constructs a copy of <i>other</i>.</p>
 
192
<p>This operation takes <a href="containers.html#constant-time">constant time</a>, because <a href="qlist.html">QList</a> is <a href="shclass.html#implicitly-shared">implicitly shared</a>. This makes returning a <a href="qlist.html">QList</a> from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes <a href="containers.html#linear-time">linear time</a>.</p>
 
193
<p>See also <a href="qlist.html#operator-eq">operator=</a>().</p>
 
194
<h3 class="fn"><a name="dtor.QList"></a>QList::~QList ()</h3>
 
195
<p>Destroys the list. References to the values in the list and all iterators of this list become invalid.</p>
 
196
<h3 class="fn"><a name="append"></a>void QList::append ( const T &amp; <i>value</i> )</h3>
 
197
<p>Inserts <i>value</i> at the end of the list.</p>
 
198
<p>Example:</p>
 
199
<pre>&nbsp;   QList&lt;QString&gt; list;
 
200
    list.append(&quot;one&quot;);
 
201
    list.append(&quot;two&quot;);
 
202
    list.append(&quot;three&quot;);
 
203
    // list: [&quot;one&quot;, &quot;two&quot;, &quot;three&quot;]</pre>
 
204
<p>This is the same as list.insert(<a href="qlist.html#size">size</a>(), <i>value</i>).</p>
 
205
<p>This operation is typically very fast (<a href="containers.html#constant-time">constant time</a>), because <a href="qlist.html">QList</a> preallocates extra space on both sides of its internal buffer to allow for fast growth at both ends of the list.</p>
 
206
<p>See also <a href="qlist.html#operator-lt-lt">operator&lt;&lt;</a>(), <a href="qlist.html#prepend">prepend</a>(), and <a href="qlist.html#insert">insert</a>().</p>
 
207
<h3 class="fn"><a name="at"></a>const T &amp; QList::at ( int <i>i</i> ) const</h3>
 
208
<p>Returns the item at index position <i>i</i> in the list.</p>
 
209
<p><i>i</i> must be a valid index position in the list (i.e., 0 &lt;= <i>i</i> &lt; <a href="qlist.html#size">size</a>()).</p>
 
210
<p>This function is very fast (<a href="containers.html#constant-time">constant time</a>).</p>
 
211
<p>See also <a href="qlist.html#value">value</a>() and <a href="qlist.html#operator-5b-5d">operator[]</a>().</p>
 
212
<h3 class="fn"><a name="back"></a>T &amp; QList::back ()</h3>
 
213
<p>This function is provided for STL compatibility. It is equivalent to <a href="qlist.html#last">last</a>().</p>
 
214
<h3 class="fn"><a name="back-2"></a>const T &amp; QList::back () const</h3>
 
215
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
216
<h3 class="fn"><a name="begin"></a><a href="qlist-iterator.html">iterator</a> QList::begin ()</h3>
 
217
<p>Returns an <a href="containers.html#stl-style-iterators">STL-style iterator</a> pointing to the first item in the list.</p>
 
218
<p>See also <a href="qlist.html#constBegin">constBegin</a>() and <a href="qlist.html#end">end</a>().</p>
 
219
<h3 class="fn"><a name="begin-2"></a><a href="qlist-const-iterator.html">const_iterator</a> QList::begin () const</h3>
 
220
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
221
<h3 class="fn"><a name="clear"></a>void QList::clear ()</h3>
 
222
<p>Removes all items from the list.</p>
 
223
<p>See also <a href="qlist.html#removeAll">removeAll</a>().</p>
 
224
<h3 class="fn"><a name="constBegin"></a><a href="qlist-const-iterator.html">const_iterator</a> QList::constBegin () const</h3>
 
225
<p>Returns a const <a href="containers.html#stl-style-iterators">STL-style iterator</a> pointing to the first item in the list.</p>
 
226
<p>See also <a href="qlist.html#begin">begin</a>() and <a href="qlist.html#constEnd">constEnd</a>().</p>
 
227
<h3 class="fn"><a name="constEnd"></a><a href="qlist-const-iterator.html">const_iterator</a> QList::constEnd () const</h3>
 
228
<p>Returns a const <a href="containers.html#stl-style-iterators">STL-style iterator</a> pointing to the imaginary item after the last item in the list.</p>
 
229
<p>See also <a href="qlist.html#constBegin">constBegin</a>() and <a href="qlist.html#end">end</a>().</p>
 
230
<h3 class="fn"><a name="contains"></a>bool QList::contains ( const T &amp; <i>value</i> ) const</h3>
 
231
<p>Returns true if the list contains an occurrence of <i>value</i>; otherwise returns false.</p>
 
232
<p>This function requires the value type to have an implementation of <tt>operator==()</tt>.</p>
 
233
<p>See also <a href="qlist.html#indexOf">indexOf</a>() and <a href="qlist.html#count">count</a>().</p>
 
234
<h3 class="fn"><a name="count"></a>int QList::count ( const T &amp; <i>value</i> ) const</h3>
 
235
<p>Returns the number of occurrences of <i>value</i> in the list.</p>
 
236
<p>This function requires the value type to have an implementation of <tt>operator==()</tt>.</p>
 
237
<p>See also <a href="qlist.html#contains">contains</a>() and <a href="qlist.html#indexOf">indexOf</a>().</p>
 
238
<h3 class="fn"><a name="count-2"></a>int QList::count () const</h3>
 
239
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
240
<p>Returns the number of items in the list. This is effectively the same as <a href="qlist.html#size">size</a>().</p>
 
241
<h3 class="fn"><a name="empty"></a>bool QList::empty () const</h3>
 
242
<p>This function is provided for STL compatibility. It is equivalent to <a href="qlist.html#isEmpty">isEmpty</a>().</p>
 
243
<h3 class="fn"><a name="end"></a><a href="qlist-iterator.html">iterator</a> QList::end ()</h3>
 
244
<p>Returns an <a href="containers.html#stl-style-iterators">STL-style iterator</a> pointing to the imaginary item after the last item in the list.</p>
 
245
<p>See also <a href="qlist.html#begin">begin</a>() and <a href="qlist.html#constEnd">constEnd</a>().</p>
 
246
<h3 class="fn"><a name="end-2"></a><a href="qlist-const-iterator.html">const_iterator</a> QList::end () const</h3>
 
247
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
248
<h3 class="fn"><a name="erase"></a><a href="qlist-iterator.html">iterator</a> QList::erase ( <a href="qlist-iterator.html">iterator</a> <i>pos</i> )</h3>
 
249
<p>Removes the item associated with the iterator <i>pos</i> from the list, and returns an iterator to the next item in the list (which may be <a href="qlist.html#end">end</a>()).</p>
 
250
<p>See also <a href="qlist.html#insert">insert</a>() and <a href="qlist.html#removeAt">removeAt</a>().</p>
 
251
<h3 class="fn"><a name="erase-2"></a><a href="qlist-iterator.html">iterator</a> QList::erase ( <a href="qlist-iterator.html">iterator</a> <i>begin</i>, <a href="qlist-iterator.html">iterator</a> <i>end</i> )</h3>
 
252
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
253
<p>Removes all the items from <i>begin</i> up to (but not including) <i>end</i>. Returns an iterator to the same item that <i>end</i> referred to before the call.</p>
 
254
<h3 class="fn"><a name="first"></a>T &amp; QList::first ()</h3>
 
255
<p>Returns a reference to the first item in the list. This function assumes that the list isn't empty.</p>
 
256
<p>See also <a href="qlist.html#last">last</a>() and <a href="qlist.html#isEmpty">isEmpty</a>().</p>
 
257
<h3 class="fn"><a name="first-2"></a>const T &amp; QList::first () const</h3>
 
258
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
259
<h3 class="fn"><a name="fromSet"></a>QList&lt;T&gt; QList::fromSet ( const <a href="qset.html">QSet</a>&lt;T&gt; &amp; <i>set</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
260
<p>Returns a <a href="qlist.html">QList</a> object with the data contained in <i>set</i>. The order of the elements in the <a href="qlist.html">QList</a> is undefined.</p>
 
261
<p>Example:</p>
 
262
<pre>&nbsp;   QSet&lt;double&gt; set;
 
263
    set &lt;&lt; &quot;red&quot; &lt;&lt; &quot;green&quot; &lt;&lt; &quot;blue&quot; &lt;&lt; ... &lt;&lt; &quot;black&quot;;
 
264
 
 
265
    QList&lt;double&gt; list = QList&lt;double&gt;::fromSet(set);
 
266
    qSort(list);</pre>
 
267
<p>See also <a href="qlist.html#fromVector">fromVector</a>(), <a href="qlist.html#toSet">toSet</a>(), <a href="qset.html#toList">QSet::toList</a>(), and <a href="qtalgorithms.html#qSort">qSort</a>().</p>
 
268
<h3 class="fn"><a name="fromStdList"></a>QList&lt;T&gt; QList::fromStdList ( const std::list&lt;T&gt; &amp; <i>list</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
269
<p>Returns a <a href="qlist.html">QList</a> object with the data contained in <i>list</i>. The order of the elements in the <a href="qlist.html">QList</a> is the same as in <i>list</i>.</p>
 
270
<p>Example:</p>
 
271
<pre>&nbsp;   std::list&lt;double&gt; stdlist;
 
272
    list.push_back(1.2);
 
273
    list.push_back(0.5);
 
274
    list.push_back(3.14);
 
275
 
 
276
    QList&lt;double&gt; list = QList&lt;double&gt;::fromStdList(stdlist);</pre>
 
277
<p>See also <a href="qlist.html#toStdList">toStdList</a>() and <a href="qvector.html#fromStdVector">QVector::fromStdVector</a>().</p>
 
278
<h3 class="fn"><a name="fromVector"></a>QList&lt;T&gt; QList::fromVector ( const <a href="qvector.html">QVector</a>&lt;T&gt; &amp; <i>vector</i> )&nbsp;&nbsp;<tt> [static]</tt></h3>
 
279
<p>Returns a <a href="qlist.html">QList</a> object with the data contained in <i>vector</i>.</p>
 
280
<p>Example:</p>
 
281
<pre>&nbsp;   QVector&lt;double&gt; vect;
 
282
    vect &lt;&lt; &quot;red&quot; &lt;&lt; &quot;green&quot; &lt;&lt; &quot;blue&quot; &lt;&lt; &quot;black&quot;;
 
283
 
 
284
    QList&lt;double&gt; list = QVector&lt;T&gt;::fromVector(vect);
 
285
    // list: [&quot;red&quot;, &quot;green&quot;, &quot;blue&quot;, &quot;black&quot;]</pre>
 
286
<p>See also <a href="qlist.html#fromSet">fromSet</a>(), <a href="qlist.html#toVector">toVector</a>(), and <a href="qvector.html#toList">QVector::toList</a>().</p>
 
287
<h3 class="fn"><a name="front"></a>T &amp; QList::front ()</h3>
 
288
<p>This function is provided for STL compatibility. It is equivalent to <a href="qlist.html#first">first</a>().</p>
 
289
<h3 class="fn"><a name="front-2"></a>const T &amp; QList::front () const</h3>
 
290
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
291
<h3 class="fn"><a name="indexOf"></a>int QList::indexOf ( const T &amp; <i>value</i>, int <i>from</i> = 0 ) const</h3>
 
292
<p>Returns the index position of the first occurrence of <i>value</i> in the list, searching forward from index position <i>from</i>. Returns -1 if no item matched.</p>
 
293
<p>Example:</p>
 
294
<pre>&nbsp;   QList&lt;QString&gt; list;
 
295
    list &lt;&lt; &quot;A&quot; &lt;&lt; &quot;B&quot; &lt;&lt; &quot;C&quot; &lt;&lt; &quot;B&quot; &lt;&lt; &quot;A&quot;;
 
296
    list.indexOf(&quot;B&quot;);          // returns 1
 
297
    list.indexOf(&quot;B&quot;, 1);       // returns 1
 
298
    list.indexOf(&quot;B&quot;, 2);       // returns 3
 
299
    list.indexOf(&quot;X&quot;);          // returns -1</pre>
 
300
<p>This function requires the value type to have an implementation of <tt>operator==()</tt>.</p>
 
301
<p>See also <a href="qlist.html#lastIndexOf">lastIndexOf</a>() and <a href="qlist.html#contains">contains</a>().</p>
 
302
<h3 class="fn"><a name="insert"></a>void QList::insert ( int <i>i</i>, const T &amp; <i>value</i> )</h3>
 
303
<p>Inserts <i>value</i> at index position <i>i</i> in the list. If <i>i</i> is 0, the value is prepended to the list. If <i>i</i> is <a href="qlist.html#size">size</a>(), the value is appended to the list.</p>
 
304
<p>Example:</p>
 
305
<pre>&nbsp;   QList&lt;QString&gt; list;
 
306
    list &lt;&lt; &quot;alpha&quot; &lt;&lt; &quot;beta&quot; &lt;&lt; &quot;delta&quot;;
 
307
    list.insert(2, &quot;gamma&quot;);
 
308
    // list: [&quot;alpha&quot;, &quot;beta&quot;, &quot;gamma&quot;, &quot;delta&quot;]</pre>
 
309
<p>See also <a href="qlist.html#append">append</a>(), <a href="qlist.html#prepend">prepend</a>(), <a href="qlist.html#replace">replace</a>(), and <a href="qlist.html#removeAt">removeAt</a>().</p>
 
310
<h3 class="fn"><a name="insert-2"></a><a href="qlist-iterator.html">iterator</a> QList::insert ( <a href="qlist-iterator.html">iterator</a> <i>before</i>, const T &amp; <i>value</i> )</h3>
 
311
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
312
<p>Inserts <i>value</i> in front of the item pointed to by the iterator <i>before</i>. Returns an iterator pointing at the inserted item.</p>
 
313
<h3 class="fn"><a name="isEmpty"></a>bool QList::isEmpty () const</h3>
 
314
<p>Returns true if the list contains no items; otherwise returns false.</p>
 
315
<p>See also <a href="qlist.html#size">size</a>().</p>
 
316
<h3 class="fn"><a name="last"></a>T &amp; QList::last ()</h3>
 
317
<p>Returns a reference to the last item in the list. This function assumes that the list isn't empty.</p>
 
318
<p>See also <a href="qlist.html#first">first</a>() and <a href="qlist.html#isEmpty">isEmpty</a>().</p>
 
319
<h3 class="fn"><a name="last-2"></a>const T &amp; QList::last () const</h3>
 
320
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
321
<h3 class="fn"><a name="lastIndexOf"></a>int QList::lastIndexOf ( const T &amp; <i>value</i>, int <i>from</i> = -1 ) const</h3>
 
322
<p>Returns the index position of the last occurrence of <i>value</i> in the list, searching backward from index position <i>from</i>. If <i>from</i> is -1 (the default), the search starts at the last item. Returns -1 if no item matched.</p>
 
323
<p>Example:</p>
 
324
<pre>&nbsp;   QList&lt;QString&gt; list;
 
325
    list &lt;&lt; &quot;A&quot; &lt;&lt; &quot;B&quot; &lt;&lt; &quot;C&quot; &lt;&lt; &quot;B&quot; &lt;&lt; &quot;A&quot;;
 
326
    list.lastIndexOf(&quot;B&quot;);      // returns 3
 
327
    list.lastIndexOf(&quot;B&quot;, 3);   // returns 3
 
328
    list.lastIndexOf(&quot;B&quot;, 2);   // returns 1
 
329
    list.lastIndexOf(&quot;X&quot;);      // returns -1</pre>
 
330
<p>This function requires the value type to have an implementation of <tt>operator==()</tt>.</p>
 
331
<p>See also <a href="qlist.html#indexOf">indexOf</a>().</p>
 
332
<h3 class="fn"><a name="mid"></a>QList&lt;T&gt; QList::mid ( int <i>pos</i>, int <i>length</i> = -1 ) const</h3>
 
333
<p>Returns a list whose elements are copied from this list, starting at position <i>pos</i>. If <i>length</i> is -1 (the default), all elements after <i>pos</i> are copied; otherwise <i>length</i> elements (or all remaining elements if there are less than <i>length</i> elements) are copied.</p>
 
334
<h3 class="fn"><a name="move"></a>void QList::move ( int <i>from</i>, int <i>to</i> )</h3>
 
335
<p>Moves the item at index position <i>from</i> to index position <i>to</i>.</p>
 
336
<p>Example:</p>
 
337
<pre>&nbsp;   QList&lt;QString&gt; list;
 
338
    list &lt;&lt; &quot;A&quot; &lt;&lt; &quot;B&quot; &lt;&lt; &quot;C&quot; &lt;&lt; &quot;D&quot; &lt;&lt; &quot;E&quot; &lt;&lt; &quot;F&quot;;
 
339
    list.move(1, 4);
 
340
    // list: [&quot;A&quot;, &quot;C&quot;, &quot;D&quot;, &quot;E&quot;, &quot;B&quot;, &quot;F&quot;]</pre>
 
341
<p>This is the same as insert(<i>to</i>, takeAt(<i>from</i>)).</p>
 
342
<p>See also <a href="qlist.html#swap">swap</a>(), <a href="qlist.html#insert">insert</a>(), and <a href="qlist.html#takeAt">takeAt</a>().</p>
 
343
<h3 class="fn"><a name="pop_back"></a>void QList::pop_back ()</h3>
 
344
<p>This function is provided for STL compatibility. It is equivalent to <a href="qlist.html#removeLast">removeLast</a>().</p>
 
345
<h3 class="fn"><a name="pop_front"></a>void QList::pop_front ()</h3>
 
346
<p>This function is provided for STL compatibility. It is equivalent to <a href="qlist.html#removeFirst">removeFirst</a>().</p>
 
347
<h3 class="fn"><a name="prepend"></a>void QList::prepend ( const T &amp; <i>value</i> )</h3>
 
348
<p>Inserts <i>value</i> at the beginning of the list.</p>
 
349
<p>Example:</p>
 
350
<pre>&nbsp;   QList&lt;QString&gt; list;
 
351
    list.prepend(&quot;one&quot;);
 
352
    list.prepend(&quot;two&quot;);
 
353
    list.prepend(&quot;three&quot;);
 
354
    // list: [&quot;three&quot;, &quot;two&quot;, &quot;one&quot;]</pre>
 
355
<p>This is the same as list.insert(0, <i>value</i>).</p>
 
356
<p>This operation is usually very fast (<a href="containers.html#constant-time">constant time</a>), because <a href="qlist.html">QList</a> preallocates extra space on both sides of its internal buffer to allow for fast growth at both ends of the list.</p>
 
357
<p>See also <a href="qlist.html#append">append</a>() and <a href="qlist.html#insert">insert</a>().</p>
 
358
<h3 class="fn"><a name="push_back"></a>void QList::push_back ( const T &amp; <i>value</i> )</h3>
 
359
<p>This function is provided for STL compatibility. It is equivalent to append(<i>value</i>).</p>
 
360
<h3 class="fn"><a name="push_front"></a>void QList::push_front ( const T &amp; <i>value</i> )</h3>
 
361
<p>This function is provided for STL compatibility. It is equivalent to prepend(<i>value</i>).</p>
 
362
<h3 class="fn"><a name="removeAll"></a>int QList::removeAll ( const T &amp; <i>value</i> )</h3>
 
363
<p>Removes all occurrences of <i>value</i> in the list and returns the number of entries removed.</p>
 
364
<p>Example:</p>
 
365
<pre>&nbsp;   QList&lt;QString&gt; list;
 
366
    list &lt;&lt; &quot;sun&quot; &lt;&lt; &quot;cloud&quot; &lt;&lt; &quot;sun&quot; &lt;&lt; &quot;rain&quot;;
 
367
    list.removeAll(&quot;sun&quot;);
 
368
    // list: [&quot;cloud&quot;, &quot;rain&quot;]</pre>
 
369
<p>This function requires the value type to have an implementation of <tt>operator==()</tt>.</p>
 
370
<p>See also <a href="qlist.html#removeAt">removeAt</a>(), <a href="qlist.html#takeAt">takeAt</a>(), and <a href="qlist.html#replace">replace</a>().</p>
 
371
<h3 class="fn"><a name="removeAt"></a>void QList::removeAt ( int <i>i</i> )</h3>
 
372
<p>Removes the item at index position <i>i</i>.</p>
 
373
<p><i>i</i> must be a valid index position in the list (i.e., 0 &lt;= <i>i</i> &lt; <a href="qlist.html#size">size</a>()).</p>
 
374
<p>See also <a href="qlist.html#takeAt">takeAt</a>(), <a href="qlist.html#removeFirst">removeFirst</a>(), and <a href="qlist.html#removeLast">removeLast</a>().</p>
 
375
<h3 class="fn"><a name="removeFirst"></a>void QList::removeFirst ()</h3>
 
376
<p>Removes the first item in the list.</p>
 
377
<p>This is the same as removeAt(0).</p>
 
378
<p>See also <a href="qlist.html#removeAt">removeAt</a>() and <a href="qlist.html#takeFirst">takeFirst</a>().</p>
 
379
<h3 class="fn"><a name="removeLast"></a>void QList::removeLast ()</h3>
 
380
<p>Removes the last item in the list.</p>
 
381
<p>This is the same as removeAt(<a href="qlist.html#size">size</a>() - 1).</p>
 
382
<p>See also <a href="qlist.html#removeAt">removeAt</a>() and <a href="qlist.html#takeLast">takeLast</a>().</p>
 
383
<h3 class="fn"><a name="replace"></a>void QList::replace ( int <i>i</i>, const T &amp; <i>value</i> )</h3>
 
384
<p>Replaces the item at index position <i>i</i> with <i>value</i>.</p>
 
385
<p><i>i</i> must be a valid index position in the list (i.e., 0 &lt;= <i>i</i> &lt; <a href="qlist.html#size">size</a>()).</p>
 
386
<p>See also <a href="qlist.html#operator-5b-5d">operator[]</a>() and <a href="qlist.html#removeAt">removeAt</a>().</p>
 
387
<h3 class="fn"><a name="size"></a>int QList::size () const</h3>
 
388
<p>Returns the number of items in the list.</p>
 
389
<p>See also <a href="qlist.html#isEmpty">isEmpty</a>() and <a href="qlist.html#count">count</a>().</p>
 
390
<h3 class="fn"><a name="swap"></a>void QList::swap ( int <i>i</i>, int <i>j</i> )</h3>
 
391
<p>Exchange the item at index position <i>i</i> with the item at index position <i>j</i>.</p>
 
392
<p>Example:</p>
 
393
<pre>&nbsp;   QList&lt;QString&gt; list;
 
394
    list &lt;&lt; &quot;A&quot; &lt;&lt; &quot;B&quot; &lt;&lt; &quot;C&quot; &lt;&lt; &quot;D&quot; &lt;&lt; &quot;E&quot; &lt;&lt; &quot;F&quot;;
 
395
    list.swap(1, 4);
 
396
    // list: [&quot;A&quot;, &quot;E&quot;, &quot;C&quot;, &quot;D&quot;, &quot;B&quot;, &quot;F&quot;]</pre>
 
397
<p>See also <a href="qlist.html#move">move</a>().</p>
 
398
<h3 class="fn"><a name="takeAt"></a>T QList::takeAt ( int <i>i</i> )</h3>
 
399
<p>Removes the item at index position <i>i</i> and returns it.</p>
 
400
<p><i>i</i> must be a valid index position in the list (i.e., 0 &lt;= <i>i</i> &lt; <a href="qlist.html#size">size</a>()).</p>
 
401
<p>If you don't use the return value, <a href="qlist.html#removeAt">removeAt</a>() is more efficient.</p>
 
402
<p>See also <a href="qlist.html#removeAt">removeAt</a>(), <a href="qlist.html#takeFirst">takeFirst</a>(), and <a href="qlist.html#takeLast">takeLast</a>().</p>
 
403
<h3 class="fn"><a name="takeFirst"></a>T QList::takeFirst ()</h3>
 
404
<p>Removes the first item in the list and returns it.</p>
 
405
<p>This is the same as takeAt(0).</p>
 
406
<p>This operation is very fast (<a href="containers.html#constant-time">constant time</a>), because <a href="qlist.html">QList</a> preallocates extra space on both sides of its internal buffer to allow for fast growth at both ends of the list.</p>
 
407
<p>If you don't use the return value, <a href="qlist.html#removeFirst">removeFirst</a>() is more efficient.</p>
 
408
<p>See also <a href="qlist.html#takeLast">takeLast</a>(), <a href="qlist.html#takeAt">takeAt</a>(), and <a href="qlist.html#removeFirst">removeFirst</a>().</p>
 
409
<h3 class="fn"><a name="takeLast"></a>T QList::takeLast ()</h3>
 
410
<p>Removes the last item in the list and returns it.</p>
 
411
<p>This is the same as takeAt(<a href="qlist.html#size">size</a>() - 1).</p>
 
412
<p>This operation is very fast (<a href="containers.html#constant-time">constant time</a>), because <a href="qlist.html">QList</a> preallocates extra space on both sides of its internal buffer to allow for fast growth at both ends of the list.</p>
 
413
<p>If you don't use the return value, <a href="qlist.html#removeLast">removeLast</a>() is more efficient.</p>
 
414
<p>See also <a href="qlist.html#takeFirst">takeFirst</a>(), <a href="qlist.html#takeAt">takeAt</a>(), and <a href="qlist.html#removeLast">removeLast</a>().</p>
 
415
<h3 class="fn"><a name="toSet"></a><a href="qset.html">QSet</a>&lt;T&gt; QList::toSet () const</h3>
 
416
<p>Returns a <a href="qset.html">QSet</a> object with the data contained in this <a href="qlist.html">QList</a>. Since <a href="qset.html">QSet</a> doesn't allow duplicates, the resulting <a href="qset.html">QSet</a> might be smaller than the original list was.</p>
 
417
<p>Example:</p>
 
418
<pre>&nbsp;   QStringList list;
 
419
    list &lt;&lt; &quot;Julia&quot; &lt;&lt; &quot;Mike&quot; &lt;&lt; &quot;Mike&quot; &lt;&lt; &quot;Julia&quot; &lt;&lt; &quot;Julia&quot;;
 
420
 
 
421
    QSet&lt;QString&gt; set = list.toSet();
 
422
    set.contains(&quot;Julia&quot;);  // returns true
 
423
    set.contains(&quot;Mike&quot;);   // returns true
 
424
    set.size();             // returns 2</pre>
 
425
<p>See also <a href="qlist.html#toVector">toVector</a>(), <a href="qlist.html#fromSet">fromSet</a>(), and <a href="qset.html#fromList">QSet::fromList</a>().</p>
 
426
<h3 class="fn"><a name="toStdList"></a>std::list&lt;T&gt; QList::toStdList () const</h3>
 
427
<p>Returns a std::list object with the data contained in this <a href="qlist.html">QList</a>. Example:</p>
 
428
<pre>&nbsp;   QList&lt;double&gt; list;
 
429
    list &lt;&lt; 1.2 &lt;&lt; 0.5 &lt;&lt; 3.14;
 
430
 
 
431
    std::list&lt;double&gt; stdlist = list.toStdList();</pre>
 
432
<p>See also <a href="qlist.html#fromStdList">fromStdList</a>() and <a href="qvector.html#toStdVector">QVector::toStdVector</a>().</p>
 
433
<h3 class="fn"><a name="toVector"></a><a href="qvector.html">QVector</a>&lt;T&gt; QList::toVector () const</h3>
 
434
<p>Returns a <a href="qvector.html">QVector</a> object with the data contained in this <a href="qlist.html">QList</a>.</p>
 
435
<p>Example:</p>
 
436
<pre>&nbsp;   QStringList list;
 
437
    list &lt;&lt; &quot;Sven&quot; &lt;&lt; &quot;Kim&quot; &lt;&lt; &quot;Ola&quot;;
 
438
 
 
439
    QVector&lt;QString&gt; vect = list.toVector();
 
440
    // vect: [&quot;Sven&quot;, &quot;Kim&quot;, &quot;Ola&quot;]</pre>
 
441
<p>See also <a href="qlist.html#toSet">toSet</a>(), <a href="qlist.html#fromVector">fromVector</a>(), and <a href="qvector.html#fromList">QVector::fromList</a>().</p>
 
442
<h3 class="fn"><a name="value"></a>T QList::value ( int <i>i</i> ) const</h3>
 
443
<p>Returns the value at index position <i>i</i> in the list.</p>
 
444
<p>If the index <i>i</i> is out of bounds, the function returns a <a href="containers.html#default-constructed-values">default-constructed value</a>. If you are certain that the index is going to be within bounds, you can use <a href="qlist.html#at">at</a>() instead, which is slightly faster.</p>
 
445
<p>See also <a href="qlist.html#at">at</a>() and <a href="qlist.html#operator-5b-5d">operator[]</a>().</p>
 
446
<h3 class="fn"><a name="value-2"></a>T QList::value ( int <i>i</i>, const T &amp; <i>defaultValue</i> ) const</h3>
 
447
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
448
<p>If the index <i>i</i> is out of bounds, the function returns <i>defaultValue</i>.</p>
 
449
<h3 class="fn"><a name="operator-not-eq"></a>bool QList::operator!= ( const QList &amp; <i>other</i> ) const</h3>
 
450
<p>Returns true if <i>other</i> is not equal to this list; otherwise returns false.</p>
 
451
<p>Two lists are considered equal if they contain the same values in the same order.</p>
 
452
<p>This function requires the value type to have an implementation of <tt>operator==()</tt>.</p>
 
453
<p>See also <a href="qlist.html#operator-eq-eq">operator==</a>().</p>
 
454
<h3 class="fn"><a name="operator-2b"></a>QList QList::operator+ ( const QList &amp; <i>other</i> ) const</h3>
 
455
<p>Returns a list that contains all the items in this list followed by all the items in the <i>other</i> list.</p>
 
456
<p>See also <a href="qlist.html#operator-2b-eq">operator+=</a>().</p>
 
457
<h3 class="fn"><a name="operator-2b-eq"></a>QList &amp; QList::operator+= ( const QList &amp; <i>other</i> )</h3>
 
458
<p>Appends the items of the <i>other</i> list to this list and returns a reference to this list.</p>
 
459
<p>See also <a href="qlist.html#operator-2b">operator+</a>() and <a href="qlist.html#append">append</a>().</p>
 
460
<h3 class="fn"><a name="operator-2b-eq-2"></a>QList &amp; QList::operator+= ( const T &amp; <i>value</i> )</h3>
 
461
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
462
<p>Appends <i>value</i> to the list.</p>
 
463
<p>See also <a href="qlist.html#append">append</a>() and <a href="qlist.html#operator-lt-lt">operator&lt;&lt;</a>().</p>
 
464
<h3 class="fn"><a name="operator-lt-lt"></a>QList &amp; QList::operator&lt;&lt; ( const QList &amp; <i>other</i> )</h3>
 
465
<p>Appends the items of the <i>other</i> list to this list and returns a reference to this list.</p>
 
466
<p>See also <a href="qlist.html#operator-2b-eq">operator+=</a>() and <a href="qlist.html#append">append</a>().</p>
 
467
<h3 class="fn"><a name="operator-lt-lt-2"></a>QList &amp; QList::operator&lt;&lt; ( const T &amp; <i>value</i> )</h3>
 
468
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
469
<p>Appends <i>value</i> to the list.</p>
 
470
<h3 class="fn"><a name="operator-eq"></a>QList &amp; QList::operator= ( const QList &amp; <i>other</i> )</h3>
 
471
<p>Assigns <i>other</i> to this list and returns a reference to this list.</p>
 
472
<h3 class="fn"><a name="operator-eq-eq"></a>bool QList::operator== ( const QList &amp; <i>other</i> ) const</h3>
 
473
<p>Returns true if <i>other</i> is equal to this list; otherwise returns false.</p>
 
474
<p>Two lists are considered equal if they contain the same values in the same order.</p>
 
475
<p>This function requires the value type to have an implementation of <tt>operator==()</tt>.</p>
 
476
<p>See also <a href="qlist.html#operator-not-eq">operator!=</a>().</p>
 
477
<h3 class="fn"><a name="operator-5b-5d"></a>T &amp; QList::operator[] ( int <i>i</i> )</h3>
 
478
<p>Returns the item at index position <i>i</i> as a modifiable reference.</p>
 
479
<p><i>i</i> must be a valid index position in the list (i.e., 0 &lt;= <i>i</i> &lt; <a href="qlist.html#size">size</a>()).</p>
 
480
<p>This function is very fast (<a href="containers.html#constant-time">constant time</a>).</p>
 
481
<p>See also <a href="qlist.html#at">at</a>() and <a href="qlist.html#value">value</a>().</p>
 
482
<h3 class="fn"><a name="operator-5b-5d-2"></a>const T &amp; QList::operator[] ( int <i>i</i> ) const</h3>
 
483
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
484
<p>Same as <a href="qlist.html#at">at</a>().</p>
 
485
<hr />
 
486
<h2>Related Non-Members</h2>
 
487
<h3 class="fn"><a name="operator-lt-lt-5"></a><a href="qdatastream.html">QDataStream</a> &amp; operator&lt;&lt; ( <a href="qdatastream.html">QDataStream</a> &amp; <i>out</i>, const QList&lt;T&gt; &amp; <i>list</i> )</h3>
 
488
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
489
<p>Writes the list <i>list</i> to stream <i>out</i>.</p>
 
490
<p>This function requires the value type to implement <tt>operator&lt;&lt;()</tt>.</p>
 
491
<p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.</p>
 
492
<h3 class="fn"><a name="operator-gt-gt-5"></a><a href="qdatastream.html">QDataStream</a> &amp; operator&gt;&gt; ( <a href="qdatastream.html">QDataStream</a> &amp; <i>in</i>, QList&lt;T&gt; &amp; <i>list</i> )</h3>
 
493
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
494
<p>Reads a list from stream <i>in</i> into <i>list</i>.</p>
 
495
<p>This function requires the value type to implement <tt>operator&gt;&gt;()</tt>.</p>
 
496
<p>See also <a href="datastreamformat.html">Format of the QDataStream operators</a>.</p>
 
497
<p /><address><hr /><div align="center">
 
498
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
499
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
500
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
501
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
502
</tr></table></div></address></body>
 
503
</html>