<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <!-- qlist.cpp --> <title>Qt 4.8: QList Class Reference</title> <link rel="stylesheet" type="text/css" href="style/style.css" /> <script src="scripts/jquery.js" type="text/javascript"></script> <script src="scripts/functions.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="style/superfish.css" /> <link rel="stylesheet" type="text/css" href="style/narrow.css" /> <!--[if IE]> <meta name="MSSmartTagsPreventParsing" content="true"> <meta http-equiv="imagetoolbar" content="no"> <![endif]--> <!--[if lt IE 7]> <link rel="stylesheet" type="text/css" href="style/style_ie6.css"> <![endif]--> <!--[if IE 7]> <link rel="stylesheet" type="text/css" href="style/style_ie7.css"> <![endif]--> <!--[if IE 8]> <link rel="stylesheet" type="text/css" href="style/style_ie8.css"> <![endif]--> <script src="scripts/superfish.js" type="text/javascript"></script> <script src="scripts/narrow.js" type="text/javascript"></script> </head> <body class="" onload="CheckEmptyAndLoadList();"> <div class="header" id="qtdocheader"> <div class="content"> <div id="nav-logo"> <a href="index.html">Home</a></div> <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a> <div id="narrowsearch"></div> <div id="nav-topright"> <ul> <li class="nav-topright-home"><a href="http://qt.digia.com/">Qt HOME</a></li> <li class="nav-topright-dev"><a href="http://qt-project.org/">DEV</a></li> <li class="nav-topright-doc nav-topright-doc-active"><a href="http://qt-project.org/doc/"> DOC</a></li> <li class="nav-topright-blog"><a href="http://blog.qt.digia.com/">BLOG</a></li> </ul> </div> <div id="shortCut"> <ul> <li class="shortCut-topleft-inactive"><span><a href="index.html">Qt 4.8</a></span></li> <li class="shortCut-topleft-active"><a href="http://qt-project.org/doc/">ALL VERSIONS </a></li> </ul> </div> <ul class="sf-menu" id="narrowmenu"> <li><a href="#">API Lookup</a> <ul> <li><a href="classes.html">Class index</a></li> <li><a href="functions.html">Function index</a></li> <li><a href="modules.html">Modules</a></li> <li><a href="namespaces.html">Namespaces</a></li> <li><a href="qtglobal.html">Global Declarations</a></li> <li><a href="qdeclarativeelements.html">QML elements</a></li> </ul> </li> <li><a href="#">Qt Topics</a> <ul> <li><a href="qt-basic-concepts.html">Programming with Qt</a></li> <li><a href="qtquick.html">Device UIs & Qt Quick</a></li> <li><a href="qt-gui-concepts.html">UI Design with Qt</a></li> <li><a href="supported-platforms.html">Supported Platforms</a></li> <li><a href="technology-apis.html">Qt and Key Technologies</a></li> <li><a href="best-practices.html">How-To's and Best Practices</a></li> </ul> </li> <li><a href="#">Examples</a> <ul> <li><a href="all-examples.html">Examples</a></li> <li><a href="tutorials.html">Tutorials</a></li> <li><a href="demos.html">Demos</a></li> <li><a href="qdeclarativeexamples.html">QML Examples</a></li> </ul> </li> </ul> </div> </div> <div class="wrapper"> <div class="hd"> <span></span> </div> <div class="bd group"> <div class="sidebar"> <div class="searchlabel"> Search index:</div> <div class="search" id="sidebarsearch"> <form id="qtdocsearch" action="" onsubmit="return false;"> <fieldset> <input type="text" name="searchstring" id="pageType" value="" /> <div id="resultdialog"> <a href="#" id="resultclose">Close</a> <p id="resultlinks" class="all"><a href="#" id="showallresults">All</a> | <a href="#" id="showapiresults">API</a> | <a href="#" id="showarticleresults">Articles</a> | <a href="#" id="showexampleresults">Examples</a></p> <p id="searchcount" class="all"><span id="resultcount"></span><span id="apicount"></span><span id="articlecount"></span><span id="examplecount"></span> results:</p> <ul id="resultlist" class="all"> </ul> </div> </fieldset> </form> </div> <div class="box first bottombar" id="lookup"> <h2 title="API Lookup"><span></span> API Lookup</h2> <div id="list001" class="list"> <ul id="ul001" > <li class="defaultLink"><a href="classes.html">Class index</a></li> <li class="defaultLink"><a href="functions.html">Function index</a></li> <li class="defaultLink"><a href="modules.html">Modules</a></li> <li class="defaultLink"><a href="namespaces.html">Namespaces</a></li> <li class="defaultLink"><a href="qtglobal.html">Global Declarations</a></li> <li class="defaultLink"><a href="qdeclarativeelements.html">QML elements</a></li> </ul> </div> </div> <div class="box bottombar" id="topics"> <h2 title="Qt Topics"><span></span> Qt Topics</h2> <div id="list002" class="list"> <ul id="ul002" > <li class="defaultLink"><a href="qt-basic-concepts.html">Programming with Qt</a></li> <li class="defaultLink"><a href="qtquick.html">Device UIs & Qt Quick</a></li> <li class="defaultLink"><a href="qt-gui-concepts.html">UI Design with Qt</a></li> <li class="defaultLink"><a href="supported-platforms.html">Supported Platforms</a></li> <li class="defaultLink"><a href="technology-apis.html">Qt and Key Technologies</a></li> <li class="defaultLink"><a href="best-practices.html">How-To's and Best Practices</a></li> </ul> </div> </div> <div class="box" id="examples"> <h2 title="Examples"><span></span> Examples</h2> <div id="list003" class="list"> <ul id="ul003"> <li class="defaultLink"><a href="all-examples.html">Examples</a></li> <li class="defaultLink"><a href="tutorials.html">Tutorials</a></li> <li class="defaultLink"><a href="demos.html">Demos</a></li> <li class="defaultLink"><a href="qdeclarativeexamples.html">QML Examples</a></li> </ul> </div> </div> </div> <div class="wrap"> <div class="toolbar"> <div class="breadcrumb toolblock"> <ul> <li class="first"><a href="index.html">Home</a></li> <!-- Breadcrumbs go here --> <li><a href="modules.html">Modules</a></li> <li><a href="qtcore.html">QtCore</a></li> <li>QList</li> </ul> </div> <div class="toolbuttons toolblock"> <ul> <li id="smallA" class="t_button">A</li> <li id="medA" class="t_button active">A</li> <li id="bigA" class="t_button">A</li> <li id="print" class="t_button"><a href="javascript:this.print();"> <span>Print</span></a></li> </ul> </div> </div> <div class="content mainContent"> <div class="toc"> <h3><a name="toc">Contents</a></h3> <ul> <li class="level1"><a href="#public-types">Public Types</a></li> <li class="level1"><a href="#public-functions">Public Functions</a></li> <li class="level1"><a href="#static-public-members">Static Public Members</a></li> <li class="level1"><a href="#related-non-members">Related Non-Members</a></li> <li class="level1"><a href="#details">Detailed Description</a></li> </ul> </div> <h1 class="title">QList Class Reference</h1> <!-- $$$QList-brief --> <p>The QList class is a template class that provides lists. <a href="#details">More...</a></p> <!-- @@@QList --> <pre class="cpp"> <span class="preprocessor">#include <QList></span></pre><p><b>Inherited by: </b><a href="qitemselection.html">QItemSelection</a>, <a href="qqueue.html">QQueue</a>, <a href="qsignalspy.html">QSignalSpy</a>, <a href="qstringlist.html">QStringList</a>, and <a href="qtesteventlist.html">QTestEventList</a>.</p> <p><b>Note:</b> All functions in this class are <a href="threads-reentrancy.html#reentrant">reentrant</a>.</p> <ul> <li><a href="qlist-members.html">List of all members, including inherited members</a></li> <li><a href="qlist-qt3.html">Qt 3 support members</a></li> </ul> <a name="public-types"></a> <h2>Public Types</h2> <table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> class </td><td class="memItemRight bottomAlign"><b><a href="qlist-const-iterator.html">const_iterator</a></b></td></tr> <tr><td class="memItemLeft rightAlign topAlign"> class </td><td class="memItemRight bottomAlign"><b><a href="qlist-iterator.html">iterator</a></b></td></tr> <tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#ConstIterator-typedef">ConstIterator</a></b></td></tr> <tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#Iterator-typedef">Iterator</a></b></td></tr> <tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#const_pointer-typedef">const_pointer</a></b></td></tr> <tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#const_reference-typedef">const_reference</a></b></td></tr> <tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#difference_type-typedef">difference_type</a></b></td></tr> <tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#pointer-typedef">pointer</a></b></td></tr> <tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#reference-typedef">reference</a></b></td></tr> <tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#size_type-typedef">size_type</a></b></td></tr> <tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#value_type-typedef">value_type</a></b></td></tr> </table> <a name="public-functions"></a> <h2>Public Functions</h2> <table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#QList">QList</a></b> ()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#QList-2">QList</a></b> ( const QList<T> & <i>other</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#QList-3">QList</a></b> ( std::initializer_list<T> <i>args</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#dtor.QList">~QList</a></b> ()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#append">append</a></b> ( const T & <i>value</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#append-2">append</a></b> ( const QList<T> & <i>value</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> const T & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#at">at</a></b> ( int <i>i</i> ) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> T & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#back">back</a></b> ()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> const T & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#back-2">back</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> iterator </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#begin">begin</a></b> ()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> const_iterator </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#begin-2">begin</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#clear">clear</a></b> ()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> const_iterator </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#constBegin">constBegin</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> const_iterator </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#constEnd">constEnd</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#contains">contains</a></b> ( const T & <i>value</i> ) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#count">count</a></b> ( const T & <i>value</i> ) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#count-2">count</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#empty">empty</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> iterator </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#end">end</a></b> ()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> const_iterator </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#end-2">end</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#endsWith">endsWith</a></b> ( const T & <i>value</i> ) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> iterator </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#erase">erase</a></b> ( iterator <i>pos</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> iterator </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#erase-2">erase</a></b> ( iterator <i>begin</i>, iterator <i>end</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> T & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#first">first</a></b> ()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> const T & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#first-2">first</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> T & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#front">front</a></b> ()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> const T & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#front-2">front</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#indexOf">indexOf</a></b> ( const T & <i>value</i>, int <i>from</i> = 0 ) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#insert">insert</a></b> ( int <i>i</i>, const T & <i>value</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> iterator </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#insert-2">insert</a></b> ( iterator <i>before</i>, const T & <i>value</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#isEmpty">isEmpty</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> T & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#last">last</a></b> ()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> const T & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#last-2">last</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#lastIndexOf">lastIndexOf</a></b> ( const T & <i>value</i>, int <i>from</i> = -1 ) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#length">length</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QList<T> </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#mid">mid</a></b> ( int <i>pos</i>, int <i>length</i> = -1 ) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#move">move</a></b> ( int <i>from</i>, int <i>to</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#pop_back">pop_back</a></b> ()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#pop_front">pop_front</a></b> ()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#prepend">prepend</a></b> ( const T & <i>value</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#push_back">push_back</a></b> ( const T & <i>value</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#push_front">push_front</a></b> ( const T & <i>value</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#removeAll">removeAll</a></b> ( const T & <i>value</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#removeAt">removeAt</a></b> ( int <i>i</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#removeFirst">removeFirst</a></b> ()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#removeLast">removeLast</a></b> ()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#removeOne">removeOne</a></b> ( const T & <i>value</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#replace">replace</a></b> ( int <i>i</i>, const T & <i>value</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#reserve">reserve</a></b> ( int <i>alloc</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#size">size</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#startsWith">startsWith</a></b> ( const T & <i>value</i> ) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#swap">swap</a></b> ( QList<T> & <i>other</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#swap-2">swap</a></b> ( int <i>i</i>, int <i>j</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> T </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#takeAt">takeAt</a></b> ( int <i>i</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> T </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#takeFirst">takeFirst</a></b> ()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> T </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#takeLast">takeLast</a></b> ()</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QSet<T> </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#toSet">toSet</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> std::list<T> </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#toStdList">toStdList</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QVector<T> </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#toVector">toVector</a></b> () const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> T </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#value">value</a></b> ( int <i>i</i> ) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> T </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#value-2">value</a></b> ( int <i>i</i>, const T & <i>defaultValue</i> ) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#operator-not-eq">operator!=</a></b> ( const QList<T> & <i>other</i> ) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QList<T> </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#operator-2b">operator+</a></b> ( const QList<T> & <i>other</i> ) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QList<T> & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#operator-2b-eq">operator+=</a></b> ( const QList<T> & <i>other</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QList<T> & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#operator-2b-eq-2">operator+=</a></b> ( const T & <i>value</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QList<T> & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#operator-lt-lt">operator<<</a></b> ( const QList<T> & <i>other</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QList<T> & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#operator-lt-lt-2">operator<<</a></b> ( const T & <i>value</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QList<T> & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#operator-eq">operator=</a></b> ( const QList<T> & <i>other</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#operator-eq-eq">operator==</a></b> ( const QList<T> & <i>other</i> ) const</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> T & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#operator-5b-5d">operator[]</a></b> ( int <i>i</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> const T & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#operator-5b-5d-2">operator[]</a></b> ( int <i>i</i> ) const</td></tr> </table> <a name="static-public-members"></a> <h2>Static Public Members</h2> <table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> QList<T> </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#fromSet">fromSet</a></b> ( const QSet<T> & <i>set</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QList<T> </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#fromStdList">fromStdList</a></b> ( const std::list<T> & <i>list</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QList<T> </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#fromVector">fromVector</a></b> ( const QVector<T> & <i>vector</i> )</td></tr> </table> <a name="related-non-members"></a> <h2>Related Non-Members</h2> <table class="alignedsummary"> <tr><td class="memItemLeft rightAlign topAlign"> QDataStream & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#operator-lt-lt-11">operator<<</a></b> ( QDataStream & <i>out</i>, const QList<T> & <i>list</i> )</td></tr> <tr><td class="memItemLeft rightAlign topAlign"> QDataStream & </td><td class="memItemRight bottomAlign"><b><a href="qlist.html#operator-gt-gt-8">operator>></a></b> ( QDataStream & <i>in</i>, QList<T> & <i>list</i> )</td></tr> </table> <a name="details"></a> <!-- $$$QList-description --> <div class="descr"> <h2>Detailed Description</h2> <p>The QList class is a template class that provides lists.</p> <p>QList<T> is one of Qt's generic <a href="containers.html">container classes</a>. It stores a list of values and provides fast index-based access as well as fast insertions and removals.</p> <p>QList<T>, <a href="qlinkedlist.html">QLinkedList</a><T>, and <a href="qvector.html">QVector</a><T> provide similar functionality. Here's an overview:</p> <ul> <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> <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> <li>If you want the items to occupy adjacent memory positions, use <a href="qvector.html">QVector</a>.</li> </ul> <p>Internally, QList<T> is represented as an array of pointers to items of type T. If T is itself a pointer type or a basic type that is no larger than a pointer, or if T is one of Qt's <a href="implicit-sharing.html#shared-classes">shared classes</a>, then QList<T> stores the items directly in the pointer array. For lists under a thousand items, this array representation allows for very fast insertions in the middle, and it allows 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 at both ends of its internal array. (See <a href="containers.html#algorithmic-complexity">Algorithmic Complexity</a> for details.) Note, however, that for unshared list items that are larger than a pointer, each append or insert of a new item requires allocating the new item on the heap, and this per item allocation might make <a href="qvector.html">QVector</a> a better choice in cases that do lots of appending or inserting, since <a href="qvector.html">QVector</a> allocates memory for its items in a single heap allocation.</p> <p>Note that the internal array only ever gets bigger over the life of the list. It never shrinks. The internal array is deallocated by the destructor, by <a href="qlist.html#clear">clear</a>(), and by the assignment operator, when one list is assigned to another.</p> <p>Here's an example of a QList that stores integers and a QList that stores <a href="qdate.html">QDate</a> values:</p> <pre class="cpp"> <span class="type">QList</span><span class="operator"><</span><span class="type">int</span><span class="operator">></span> integerList; <span class="type">QList</span><span class="operator"><</span><span class="type"><a href="qdate.html">QDate</a></span><span class="operator">></span> dateList;</pre> <p>Qt includes a <a href="qstringlist.html">QStringList</a> class that inherits QList<<a href="qstring.html">QString</a>> and adds a convenience function <a href="qstringlist.html#join">QStringList::join</a>(). (<a href="qstring.html#split">QString::split</a>() creates QStringLists from strings.)</p> <p>QList stores a list of items. The default constructor creates an empty list. To insert items into the list, you can use operator<<():</p> <pre class="cpp"> <span class="type">QList</span><span class="operator"><</span><span class="type"><a href="qstring.html">QString</a></span><span class="operator">></span> list; list <span class="operator"><</span><span class="operator"><</span> <span class="string">"one"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"two"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"three"</span>; <span class="comment">// list: ["one", "two", "three"]</span></pre> <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> <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> <pre class="cpp"> <span class="keyword">if</span> (list<span class="operator">[</span><span class="number">0</span><span class="operator">]</span> <span class="operator">=</span><span class="operator">=</span> <span class="string">"Bob"</span>) list<span class="operator">[</span><span class="number">0</span><span class="operator">]</span> <span class="operator">=</span> <span class="string">"Robert"</span>;</pre> <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> <pre class="cpp"> <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator"><</span> list<span class="operator">.</span>size(); <span class="operator">+</span><span class="operator">+</span>i) { <span class="keyword">if</span> (list<span class="operator">.</span>at(i) <span class="operator">=</span><span class="operator">=</span> <span class="string">"Jane"</span>) cout <span class="operator"><</span><span class="operator"><</span> <span class="string">"Found Jane at position "</span> <span class="operator"><</span><span class="operator"><</span> i <span class="operator"><</span><span class="operator"><</span> endl; }</pre> <p><a href="qlist.html#at">at</a>() can be faster than operator[](), because it never causes a <a href="implicit-sharing.html#deep-copy">deep copy</a> to occur.</p> <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> <pre class="cpp"> <span class="type">QList</span><span class="operator"><</span><span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span><span class="operator">></span> list; <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> <span class="keyword">while</span> (<span class="operator">!</span>list<span class="operator">.</span>isEmpty()) <span class="keyword">delete</span> list<span class="operator">.</span><a href="qlist.html#takeFirst">takeFirst</a>();</pre> <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> <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> <pre class="cpp"> <span class="type">int</span> i <span class="operator">=</span> list<span class="operator">.</span><a href="qlist.html#indexOf">indexOf</a>(<span class="string">"Jane"</span>); <span class="keyword">if</span> (i <span class="operator">!</span><span class="operator">=</span> <span class="operator">-</span><span class="number">1</span>) cout <span class="operator"><</span><span class="operator"><</span> <span class="string">"First occurrence of Jane is at position "</span> <span class="operator"><</span><span class="operator"><</span> i <span class="operator"><</span><span class="operator"><</span> endl;</pre> <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> <p>QList's value type must be an <a href="containers.html#assignable-data-type">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> <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> <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> <p>To make QList as efficient as possible, its member functions don't validate their input before using it. Except for <a href="qlist.html#isEmpty">isEmpty</a>(), member functions always assume the list is <i>not</i> empty. Member functions that take index values as parameters always assume their index value parameters are in the valid range. This means QList member functions can fail. If you define QT_NO_DEBUG when you compile, failures will not be detected. If you <i>don't</i> define QT_NO_DEBUG, failures will be detected using <a href="qtglobal.html#Q_ASSERT">Q_ASSERT</a>() or <a href="qtglobal.html#Q_ASSERT_X">Q_ASSERT_X</a>() with an appropriate message.</p> <p>To avoid failures when your list can be empty, call <a href="qlist.html#isEmpty">isEmpty</a>() before calling other member functions. If you must pass an index value that might not be in the valid range, check that it is less than the value returned by <a href="qlist.html#size">size</a>() but <i>not</i> less than 0.</p> </div> <p><b>See also </b><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> <!-- @@@QList --> <div class="types"> <h2>Member Type Documentation</h2> <!-- $$$ConstIterator --> <h3 class="fn"><a name="ConstIterator-typedef"></a>typedef QList::<span class="name">ConstIterator</span></h3> <p>Qt-style synonym for <a href="qlist-const-iterator.html">QList::const_iterator</a>.</p> <!-- @@@ConstIterator --> <!-- $$$Iterator --> <h3 class="fn"><a name="Iterator-typedef"></a>typedef QList::<span class="name">Iterator</span></h3> <p>Qt-style synonym for <a href="qlist-iterator.html">QList::iterator</a>.</p> <!-- @@@Iterator --> <!-- $$$const_pointer --> <h3 class="fn"><a name="const_pointer-typedef"></a>typedef QList::<span class="name">const_pointer</span></h3> <p>Typedef for const T *. Provided for STL compatibility.</p> <!-- @@@const_pointer --> <!-- $$$const_reference --> <h3 class="fn"><a name="const_reference-typedef"></a>typedef QList::<span class="name">const_reference</span></h3> <p>Typedef for const T &. Provided for STL compatibility.</p> <!-- @@@const_reference --> <!-- $$$difference_type --> <h3 class="fn"><a name="difference_type-typedef"></a>typedef QList::<span class="name">difference_type</span></h3> <p>Typedef for ptrdiff_t. Provided for STL compatibility.</p> <!-- @@@difference_type --> <!-- $$$pointer --> <h3 class="fn"><a name="pointer-typedef"></a>typedef QList::<span class="name">pointer</span></h3> <p>Typedef for T *. Provided for STL compatibility.</p> <!-- @@@pointer --> <!-- $$$reference --> <h3 class="fn"><a name="reference-typedef"></a>typedef QList::<span class="name">reference</span></h3> <p>Typedef for T &. Provided for STL compatibility.</p> <!-- @@@reference --> <!-- $$$size_type --> <h3 class="fn"><a name="size_type-typedef"></a>typedef QList::<span class="name">size_type</span></h3> <p>Typedef for int. Provided for STL compatibility.</p> <!-- @@@size_type --> <!-- $$$value_type --> <h3 class="fn"><a name="value_type-typedef"></a>typedef QList::<span class="name">value_type</span></h3> <p>Typedef for T. Provided for STL compatibility.</p> <!-- @@@value_type --> </div> <div class="func"> <h2>Member Function Documentation</h2> <!-- $$$QList[overload1]$$$QList --> <h3 class="fn"><a name="QList"></a>QList::<span class="name">QList</span> ()</h3> <p>Constructs an empty list.</p> <!-- @@@QList --> <!-- $$$QList$$$QListconstQList<T>& --> <h3 class="fn"><a name="QList-2"></a>QList::<span class="name">QList</span> ( const <span class="type">QList</span><<span class="type">T</span>> & <i>other</i> )</h3> <p>Constructs a copy of <i>other</i>.</p> <p>This operation takes <a href="containers.html#constant-time">constant time</a>, because <a href="qlist.html">QList</a> is <a href="implicit-sharing.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> <p><b>See also </b><a href="qlist.html#operator-eq">operator=</a>().</p> <!-- @@@QList --> <!-- $$$QList$$$QListstd::initializer_list<T> --> <h3 class="fn"><a name="QList-3"></a>QList::<span class="name">QList</span> ( <span class="type">std::initializer_list</span><<span class="type">T</span>> <i>args</i> )</h3> <p>Construct a list from the std::initializer_list specified by <i>args</i>.</p> <p>This constructor is only enabled if the compiler supports C++0x</p> <p>This function was introduced in Qt 4.8.</p> <!-- @@@QList --> <!-- $$$~QList[overload1]$$$~QList --> <h3 class="fn"><a name="dtor.QList"></a>QList::<span class="name">~QList</span> ()</h3> <p>Destroys the list. References to the values in the list and all iterators of this list become invalid.</p> <!-- @@@~QList --> <!-- $$$append[overload1]$$$appendconstT& --> <h3 class="fn"><a name="append"></a><span class="type">void</span> QList::<span class="name">append</span> ( const <span class="type">T</span> & <i>value</i> )</h3> <p>Inserts <i>value</i> at the end of the list.</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type"><a href="qstring.html">QString</a></span><span class="operator">></span> list; list<span class="operator">.</span>append(<span class="string">"one"</span>); list<span class="operator">.</span>append(<span class="string">"two"</span>); list<span class="operator">.</span>append(<span class="string">"three"</span>); <span class="comment">// list: ["one", "two", "three"]</span></pre> <p>This is the same as list.insert(<a href="qlist.html#size">size</a>(), <i>value</i>).</p> <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> <p><b>See also </b><a href="qlist.html#operator-lt-lt">operator<<</a>(), <a href="qlist.html#prepend">prepend</a>(), and <a href="qlist.html#insert">insert</a>().</p> <!-- @@@append --> <!-- $$$append$$$appendconstQList<T>& --> <h3 class="fn"><a name="append-2"></a><span class="type">void</span> QList::<span class="name">append</span> ( const <span class="type">QList</span><<span class="type">T</span>> & <i>value</i> )</h3> <p>This is an overloaded function.</p> <p>Appends the items of the <i>value</i> list to this list.</p> <p>This function was introduced in Qt 4.5.</p> <p><b>See also </b><a href="qlist.html#operator-lt-lt">operator<<</a>() and <a href="qlist.html#operator-2b-eq">operator+=</a>().</p> <!-- @@@append --> <!-- $$$at[overload1]$$$atint --> <h3 class="fn"><a name="at"></a>const <span class="type">T</span> & QList::<span class="name">at</span> ( <span class="type">int</span> <i>i</i> ) const</h3> <p>Returns the item at index position <i>i</i> in the list. <i>i</i> must be a valid index position in the list (i.e., 0 <= <i>i</i> < <a href="qlist.html#size">size</a>()).</p> <p>This function is very fast (<a href="containers.html#constant-time">constant time</a>).</p> <p><b>See also </b><a href="qlist.html#value">value</a>() and <a href="qlist.html#operator-5b-5d">operator[]</a>().</p> <!-- @@@at --> <!-- $$$back[overload1]$$$back --> <h3 class="fn"><a name="back"></a><span class="type">T</span> & QList::<span class="name">back</span> ()</h3> <p>This function is provided for STL compatibility. It is equivalent to <a href="qlist.html#last">last</a>(). The list must not be empty. If the list can be empty, call <a href="qlist.html#isEmpty">isEmpty</a>() before calling this function.</p> <!-- @@@back --> <!-- $$$back$$$back --> <h3 class="fn"><a name="back-2"></a>const <span class="type">T</span> & QList::<span class="name">back</span> () const</h3> <p>This is an overloaded function.</p> <!-- @@@back --> <!-- $$$begin[overload1]$$$begin --> <h3 class="fn"><a name="begin"></a><span class="type"><a href="qlist-iterator.html">iterator</a></span> QList::<span class="name">begin</span> ()</h3> <p>Returns an <a href="containers.html#stl-style-iterators">STL-style iterator</a> pointing to the first item in the list.</p> <p><b>See also </b><a href="qlist.html#constBegin">constBegin</a>() and <a href="qlist.html#end">end</a>().</p> <!-- @@@begin --> <!-- $$$begin$$$begin --> <h3 class="fn"><a name="begin-2"></a><span class="type"><a href="qlist-const-iterator.html">const_iterator</a></span> QList::<span class="name">begin</span> () const</h3> <p>This is an overloaded function.</p> <!-- @@@begin --> <!-- $$$clear[overload1]$$$clear --> <h3 class="fn"><a name="clear"></a><span class="type">void</span> QList::<span class="name">clear</span> ()</h3> <p>Removes all items from the list.</p> <p><b>See also </b><a href="qlist.html#removeAll">removeAll</a>().</p> <!-- @@@clear --> <!-- $$$constBegin[overload1]$$$constBegin --> <h3 class="fn"><a name="constBegin"></a><span class="type"><a href="qlist-const-iterator.html">const_iterator</a></span> QList::<span class="name">constBegin</span> () const</h3> <p>Returns a const <a href="containers.html#stl-style-iterators">STL-style iterator</a> pointing to the first item in the list.</p> <p><b>See also </b><a href="qlist.html#begin">begin</a>() and <a href="qlist.html#constEnd">constEnd</a>().</p> <!-- @@@constBegin --> <!-- $$$constEnd[overload1]$$$constEnd --> <h3 class="fn"><a name="constEnd"></a><span class="type"><a href="qlist-const-iterator.html">const_iterator</a></span> QList::<span class="name">constEnd</span> () const</h3> <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> <p><b>See also </b><a href="qlist.html#constBegin">constBegin</a>() and <a href="qlist.html#end">end</a>().</p> <!-- @@@constEnd --> <!-- $$$contains[overload1]$$$containsconstT& --> <h3 class="fn"><a name="contains"></a><span class="type">bool</span> QList::<span class="name">contains</span> ( const <span class="type">T</span> & <i>value</i> ) const</h3> <p>Returns true if the list contains an occurrence of <i>value</i>; otherwise returns false.</p> <p>This function requires the value type to have an implementation of <tt>operator==()</tt>.</p> <p><b>See also </b><a href="qlist.html#indexOf">indexOf</a>() and <a href="qlist.html#count">count</a>().</p> <!-- @@@contains --> <!-- $$$count[overload1]$$$countconstT& --> <h3 class="fn"><a name="count"></a><span class="type">int</span> QList::<span class="name">count</span> ( const <span class="type">T</span> & <i>value</i> ) const</h3> <p>Returns the number of occurrences of <i>value</i> in the list.</p> <p>This function requires the value type to have an implementation of <tt>operator==()</tt>.</p> <p><b>See also </b><a href="qlist.html#contains">contains</a>() and <a href="qlist.html#indexOf">indexOf</a>().</p> <!-- @@@count --> <!-- $$$count$$$count --> <h3 class="fn"><a name="count-2"></a><span class="type">int</span> QList::<span class="name">count</span> () const</h3> <p>Returns the number of items in the list. This is effectively the same as <a href="qlist.html#size">size</a>().</p> <!-- @@@count --> <!-- $$$empty[overload1]$$$empty --> <h3 class="fn"><a name="empty"></a><span class="type">bool</span> QList::<span class="name">empty</span> () const</h3> <p>This function is provided for STL compatibility. It is equivalent to <a href="qlist.html#isEmpty">isEmpty</a>() and returns true if the list is empty.</p> <!-- @@@empty --> <!-- $$$end[overload1]$$$end --> <h3 class="fn"><a name="end"></a><span class="type"><a href="qlist-iterator.html">iterator</a></span> QList::<span class="name">end</span> ()</h3> <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> <p><b>See also </b><a href="qlist.html#begin">begin</a>() and <a href="qlist.html#constEnd">constEnd</a>().</p> <!-- @@@end --> <!-- $$$end$$$end --> <h3 class="fn"><a name="end-2"></a><span class="type"><a href="qlist-const-iterator.html">const_iterator</a></span> QList::<span class="name">end</span> () const</h3> <p>This is an overloaded function.</p> <!-- @@@end --> <!-- $$$endsWith[overload1]$$$endsWithconstT& --> <h3 class="fn"><a name="endsWith"></a><span class="type">bool</span> QList::<span class="name">endsWith</span> ( const <span class="type">T</span> & <i>value</i> ) const</h3> <p>Returns true if this list is not empty and its last item is equal to <i>value</i>; otherwise returns false.</p> <p>This function was introduced in Qt 4.5.</p> <p><b>See also </b><a href="qlist.html#isEmpty">isEmpty</a>() and <a href="qlist.html#contains">contains</a>().</p> <!-- @@@endsWith --> <!-- $$$erase[overload1]$$$eraseiterator --> <h3 class="fn"><a name="erase"></a><span class="type"><a href="qlist-iterator.html">iterator</a></span> QList::<span class="name">erase</span> ( <span class="type"><a href="qlist-iterator.html">iterator</a></span> <i>pos</i> )</h3> <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> <p><b>See also </b><a href="qlist.html#insert">insert</a>() and <a href="qlist.html#removeAt">removeAt</a>().</p> <!-- @@@erase --> <!-- $$$erase$$$eraseiteratoriterator --> <h3 class="fn"><a name="erase-2"></a><span class="type"><a href="qlist-iterator.html">iterator</a></span> QList::<span class="name">erase</span> ( <span class="type"><a href="qlist-iterator.html">iterator</a></span> <i>begin</i>, <span class="type"><a href="qlist-iterator.html">iterator</a></span> <i>end</i> )</h3> <p>This is an overloaded function.</p> <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> <!-- @@@erase --> <!-- $$$first[overload1]$$$first --> <h3 class="fn"><a name="first"></a><span class="type">T</span> & QList::<span class="name">first</span> ()</h3> <p>Returns a reference to the first item in the list. The list must not be empty. If the list can be empty, call <a href="qlist.html#isEmpty">isEmpty</a>() before calling this function.</p> <p><b>See also </b><a href="qlist.html#last">last</a>() and <a href="qlist.html#isEmpty">isEmpty</a>().</p> <!-- @@@first --> <!-- $$$first$$$first --> <h3 class="fn"><a name="first-2"></a>const <span class="type">T</span> & QList::<span class="name">first</span> () const</h3> <p>This is an overloaded function.</p> <!-- @@@first --> <!-- $$$fromSet[overload1]$$$fromSetconstQSet<T>& --> <h3 class="fn"><a name="fromSet"></a><span class="type">QList</span><<span class="type">T</span>> QList::<span class="name">fromSet</span> ( const <span class="type"><a href="qset.html">QSet</a></span><<span class="type">T</span>> & <i>set</i> )<tt> [static]</tt></h3> <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> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qset.html">QSet</a></span><span class="operator"><</span><span class="type">int</span><span class="operator">></span> set; set <span class="operator"><</span><span class="operator"><</span> <span class="number">20</span> <span class="operator"><</span><span class="operator"><</span> <span class="number">30</span> <span class="operator"><</span><span class="operator"><</span> <span class="number">40</span> <span class="operator"><</span><span class="operator"><</span> <span class="operator">.</span><span class="operator">.</span><span class="operator">.</span> <span class="operator"><</span><span class="operator"><</span> <span class="number">70</span>; <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type">int</span><span class="operator">></span> list <span class="operator">=</span> <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type">int</span><span class="operator">></span><span class="operator">::</span>fromSet(set); <a href="qtalgorithms.html#qSort">qSort</a>(list);</pre> <p><b>See also </b><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> <!-- @@@fromSet --> <!-- $$$fromStdList[overload1]$$$fromStdListconststd::list<T>& --> <h3 class="fn"><a name="fromStdList"></a><span class="type">QList</span><<span class="type">T</span>> QList::<span class="name">fromStdList</span> ( const <span class="type">std::list</span><<span class="type">T</span>> & <i>list</i> )<tt> [static]</tt></h3> <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> <p>Example:</p> <pre class="cpp"> std<span class="operator">::</span>list<span class="operator"><</span><span class="type">double</span><span class="operator">></span> stdlist; list<span class="operator">.</span><a href="qlist.html#push_back">push_back</a>(<span class="number">1.2</span>); list<span class="operator">.</span><a href="qlist.html#push_back">push_back</a>(<span class="number">0.5</span>); list<span class="operator">.</span><a href="qlist.html#push_back">push_back</a>(<span class="number">3.14</span>); <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type">double</span><span class="operator">></span> list <span class="operator">=</span> <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type">double</span><span class="operator">></span><span class="operator">::</span>fromStdList(stdlist);</pre> <p><b>See also </b><a href="qlist.html#toStdList">toStdList</a>() and <a href="qvector.html#fromStdVector">QVector::fromStdVector</a>().</p> <!-- @@@fromStdList --> <!-- $$$fromVector[overload1]$$$fromVectorconstQVector<T>& --> <h3 class="fn"><a name="fromVector"></a><span class="type">QList</span><<span class="type">T</span>> QList::<span class="name">fromVector</span> ( const <span class="type"><a href="qvector.html">QVector</a></span><<span class="type">T</span>> & <i>vector</i> )<tt> [static]</tt></h3> <p>Returns a <a href="qlist.html">QList</a> object with the data contained in <i>vector</i>.</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qvector.html">QVector</a></span><span class="operator"><</span><span class="type">double</span><span class="operator">></span> vect; vect <span class="operator"><</span><span class="operator"><</span> <span class="number">20.0</span> <span class="operator"><</span><span class="operator"><</span> <span class="number">30.0</span> <span class="operator"><</span><span class="operator"><</span> <span class="number">40.0</span> <span class="operator"><</span><span class="operator"><</span> <span class="number">50.0</span>; <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type">double</span><span class="operator">></span> list <span class="operator">=</span> <span class="type"><a href="qvector.html">QVector</a></span><span class="operator"><</span>T<span class="operator">></span><span class="operator">::</span>fromVector(vect); <span class="comment">// list: [20.0, 30.0, 40.0, 50.0]</span></pre> <p><b>See also </b><a href="qlist.html#fromSet">fromSet</a>(), <a href="qlist.html#toVector">toVector</a>(), and <a href="qvector.html#toList">QVector::toList</a>().</p> <!-- @@@fromVector --> <!-- $$$front[overload1]$$$front --> <h3 class="fn"><a name="front"></a><span class="type">T</span> & QList::<span class="name">front</span> ()</h3> <p>This function is provided for STL compatibility. It is equivalent to <a href="qlist.html#first">first</a>(). The list must not be empty. If the list can be empty, call <a href="qlist.html#isEmpty">isEmpty</a>() before calling this function.</p> <!-- @@@front --> <!-- $$$front$$$front --> <h3 class="fn"><a name="front-2"></a>const <span class="type">T</span> & QList::<span class="name">front</span> () const</h3> <p>This is an overloaded function.</p> <!-- @@@front --> <!-- $$$indexOf[overload1]$$$indexOfconstT&int --> <h3 class="fn"><a name="indexOf"></a><span class="type">int</span> QList::<span class="name">indexOf</span> ( const <span class="type">T</span> & <i>value</i>, <span class="type">int</span> <i>from</i> = 0 ) const</h3> <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> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type"><a href="qstring.html">QString</a></span><span class="operator">></span> list; list <span class="operator"><</span><span class="operator"><</span> <span class="string">"A"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"B"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"C"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"B"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"A"</span>; list<span class="operator">.</span>indexOf(<span class="string">"B"</span>); <span class="comment">// returns 1</span> list<span class="operator">.</span>indexOf(<span class="string">"B"</span><span class="operator">,</span> <span class="number">1</span>); <span class="comment">// returns 1</span> list<span class="operator">.</span>indexOf(<span class="string">"B"</span><span class="operator">,</span> <span class="number">2</span>); <span class="comment">// returns 3</span> list<span class="operator">.</span>indexOf(<span class="string">"X"</span>); <span class="comment">// returns -1</span></pre> <p>This function requires the value type to have an implementation of <tt>operator==()</tt>.</p> <p>Note that <a href="qlist.html">QList</a> uses 0-based indexes, just like C++ arrays. Negative indexes are not supported with the exception of the value mentioned above.</p> <p><b>See also </b><a href="qlist.html#lastIndexOf">lastIndexOf</a>() and <a href="qlist.html#contains">contains</a>().</p> <!-- @@@indexOf --> <!-- $$$insert[overload1]$$$insertintconstT& --> <h3 class="fn"><a name="insert"></a><span class="type">void</span> QList::<span class="name">insert</span> ( <span class="type">int</span> <i>i</i>, const <span class="type">T</span> & <i>value</i> )</h3> <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> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type"><a href="qstring.html">QString</a></span><span class="operator">></span> list; list <span class="operator"><</span><span class="operator"><</span> <span class="string">"alpha"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"beta"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"delta"</span>; list<span class="operator">.</span>insert(<span class="number">2</span><span class="operator">,</span> <span class="string">"gamma"</span>); <span class="comment">// list: ["alpha", "beta", "gamma", "delta"]</span></pre> <p><b>See also </b><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> <!-- @@@insert --> <!-- $$$insert$$$insertiteratorconstT& --> <h3 class="fn"><a name="insert-2"></a><span class="type"><a href="qlist-iterator.html">iterator</a></span> QList::<span class="name">insert</span> ( <span class="type"><a href="qlist-iterator.html">iterator</a></span> <i>before</i>, const <span class="type">T</span> & <i>value</i> )</h3> <p>This is an overloaded function.</p> <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. Note that the iterator passed to the function will be invalid after the call; the returned iterator should be used instead.</p> <!-- @@@insert --> <!-- $$$isEmpty[overload1]$$$isEmpty --> <h3 class="fn"><a name="isEmpty"></a><span class="type">bool</span> QList::<span class="name">isEmpty</span> () const</h3> <p>Returns true if the list contains no items; otherwise returns false.</p> <p><b>See also </b><a href="qlist.html#size">size</a>().</p> <!-- @@@isEmpty --> <!-- $$$last[overload1]$$$last --> <h3 class="fn"><a name="last"></a><span class="type">T</span> & QList::<span class="name">last</span> ()</h3> <p>Returns a reference to the last item in the list. The list must not be empty. If the list can be empty, call <a href="qlist.html#isEmpty">isEmpty</a>() before calling this function.</p> <p><b>See also </b><a href="qlist.html#first">first</a>() and <a href="qlist.html#isEmpty">isEmpty</a>().</p> <!-- @@@last --> <!-- $$$last$$$last --> <h3 class="fn"><a name="last-2"></a>const <span class="type">T</span> & QList::<span class="name">last</span> () const</h3> <p>This is an overloaded function.</p> <!-- @@@last --> <!-- $$$lastIndexOf[overload1]$$$lastIndexOfconstT&int --> <h3 class="fn"><a name="lastIndexOf"></a><span class="type">int</span> QList::<span class="name">lastIndexOf</span> ( const <span class="type">T</span> & <i>value</i>, <span class="type">int</span> <i>from</i> = -1 ) const</h3> <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> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type"><a href="qstring.html">QString</a></span><span class="operator">></span> list; list <span class="operator"><</span><span class="operator"><</span> <span class="string">"A"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"B"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"C"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"B"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"A"</span>; list<span class="operator">.</span>lastIndexOf(<span class="string">"B"</span>); <span class="comment">// returns 3</span> list<span class="operator">.</span>lastIndexOf(<span class="string">"B"</span><span class="operator">,</span> <span class="number">3</span>); <span class="comment">// returns 3</span> list<span class="operator">.</span>lastIndexOf(<span class="string">"B"</span><span class="operator">,</span> <span class="number">2</span>); <span class="comment">// returns 1</span> list<span class="operator">.</span>lastIndexOf(<span class="string">"X"</span>); <span class="comment">// returns -1</span></pre> <p>This function requires the value type to have an implementation of <tt>operator==()</tt>.</p> <p>Note that <a href="qlist.html">QList</a> uses 0-based indexes, just like C++ arrays. Negative indexes are not supported with the exception of the value mentioned above.</p> <p><b>See also </b><a href="qlist.html#indexOf">indexOf</a>().</p> <!-- @@@lastIndexOf --> <!-- $$$length[overload1]$$$length --> <h3 class="fn"><a name="length"></a><span class="type">int</span> QList::<span class="name">length</span> () const</h3> <p>This function is identical to <a href="qlist.html#count">count</a>().</p> <p>This function was introduced in Qt 4.5.</p> <p><b>See also </b><a href="qlist.html#count">count</a>().</p> <!-- @@@length --> <!-- $$$mid[overload1]$$$midintint --> <h3 class="fn"><a name="mid"></a><span class="type">QList</span><<span class="type">T</span>> QList::<span class="name">mid</span> ( <span class="type">int</span> <i>pos</i>, <span class="type">int</span> <i>length</i> = -1 ) const</h3> <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 from <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> <!-- @@@mid --> <!-- $$$move[overload1]$$$moveintint --> <h3 class="fn"><a name="move"></a><span class="type">void</span> QList::<span class="name">move</span> ( <span class="type">int</span> <i>from</i>, <span class="type">int</span> <i>to</i> )</h3> <p>Moves the item at index position <i>from</i> to index position <i>to</i>.</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type"><a href="qstring.html">QString</a></span><span class="operator">></span> list; list <span class="operator"><</span><span class="operator"><</span> <span class="string">"A"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"B"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"C"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"D"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"E"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"F"</span>; list<span class="operator">.</span>move(<span class="number">1</span><span class="operator">,</span> <span class="number">4</span>); <span class="comment">// list: ["A", "C", "D", "E", "B", "F"]</span></pre> <p>This is the same as insert(<i>to</i>, takeAt(<i>from</i>)).This function assumes that both <i>from</i> and <i>to</i> are at least 0 but less than <a href="qlist.html#size">size</a>(). To avoid failure, test that both <i>from</i> and <i>to</i> are at least 0 and less than <a href="qlist.html#size">size</a>().</p> <p><b>See also </b><a href="qlist.html#swap">swap</a>(), <a href="qlist.html#insert">insert</a>(), and <a href="qlist.html#takeAt">takeAt</a>().</p> <!-- @@@move --> <!-- $$$pop_back[overload1]$$$pop_back --> <h3 class="fn"><a name="pop_back"></a><span class="type">void</span> QList::<span class="name">pop_back</span> ()</h3> <p>This function is provided for STL compatibility. It is equivalent to <a href="qlist.html#removeLast">removeLast</a>(). The list must not be empty. If the list can be empty, call <a href="qlist.html#isEmpty">isEmpty</a>() before calling this function.</p> <!-- @@@pop_back --> <!-- $$$pop_front[overload1]$$$pop_front --> <h3 class="fn"><a name="pop_front"></a><span class="type">void</span> QList::<span class="name">pop_front</span> ()</h3> <p>This function is provided for STL compatibility. It is equivalent to <a href="qlist.html#removeFirst">removeFirst</a>(). The list must not be empty. If the list can be empty, call <a href="qlist.html#isEmpty">isEmpty</a>() before calling this function.</p> <!-- @@@pop_front --> <!-- $$$prepend[overload1]$$$prependconstT& --> <h3 class="fn"><a name="prepend"></a><span class="type">void</span> QList::<span class="name">prepend</span> ( const <span class="type">T</span> & <i>value</i> )</h3> <p>Inserts <i>value</i> at the beginning of the list.</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type"><a href="qstring.html">QString</a></span><span class="operator">></span> list; list<span class="operator">.</span>prepend(<span class="string">"one"</span>); list<span class="operator">.</span>prepend(<span class="string">"two"</span>); list<span class="operator">.</span>prepend(<span class="string">"three"</span>); <span class="comment">// list: ["three", "two", "one"]</span></pre> <p>This is the same as list.insert(0, <i>value</i>).</p> <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> <p><b>See also </b><a href="qlist.html#append">append</a>() and <a href="qlist.html#insert">insert</a>().</p> <!-- @@@prepend --> <!-- $$$push_back[overload1]$$$push_backconstT& --> <h3 class="fn"><a name="push_back"></a><span class="type">void</span> QList::<span class="name">push_back</span> ( const <span class="type">T</span> & <i>value</i> )</h3> <p>This function is provided for STL compatibility. It is equivalent to <a href="qlist.html#append">append</a>(<i>value</i>).</p> <!-- @@@push_back --> <!-- $$$push_front[overload1]$$$push_frontconstT& --> <h3 class="fn"><a name="push_front"></a><span class="type">void</span> QList::<span class="name">push_front</span> ( const <span class="type">T</span> & <i>value</i> )</h3> <p>This function is provided for STL compatibility. It is equivalent to <a href="qlist.html#prepend">prepend</a>(<i>value</i>).</p> <!-- @@@push_front --> <!-- $$$removeAll[overload1]$$$removeAllconstT& --> <h3 class="fn"><a name="removeAll"></a><span class="type">int</span> QList::<span class="name">removeAll</span> ( const <span class="type">T</span> & <i>value</i> )</h3> <p>Removes all occurrences of <i>value</i> in the list and returns the number of entries removed.</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type"><a href="qstring.html">QString</a></span><span class="operator">></span> list; list <span class="operator"><</span><span class="operator"><</span> <span class="string">"sun"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"cloud"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"sun"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"rain"</span>; list<span class="operator">.</span>removeAll(<span class="string">"sun"</span>); <span class="comment">// list: ["cloud", "rain"]</span></pre> <p>This function requires the value type to have an implementation of <tt>operator==()</tt>.</p> <p><b>See also </b><a href="qlist.html#removeOne">removeOne</a>(), <a href="qlist.html#removeAt">removeAt</a>(), <a href="qlist.html#takeAt">takeAt</a>(), and <a href="qlist.html#replace">replace</a>().</p> <!-- @@@removeAll --> <!-- $$$removeAt[overload1]$$$removeAtint --> <h3 class="fn"><a name="removeAt"></a><span class="type">void</span> QList::<span class="name">removeAt</span> ( <span class="type">int</span> <i>i</i> )</h3> <p>Removes the item at index position <i>i</i>. <i>i</i> must be a valid index position in the list (i.e., 0 <= <i>i</i> < <a href="qlist.html#size">size</a>()).</p> <p><b>See also </b><a href="qlist.html#takeAt">takeAt</a>(), <a href="qlist.html#removeFirst">removeFirst</a>(), <a href="qlist.html#removeLast">removeLast</a>(), and <a href="qlist.html#removeOne">removeOne</a>().</p> <!-- @@@removeAt --> <!-- $$$removeFirst[overload1]$$$removeFirst --> <h3 class="fn"><a name="removeFirst"></a><span class="type">void</span> QList::<span class="name">removeFirst</span> ()</h3> <p>Removes the first item in the list. Calling this function is equivalent to calling removeAt(0). The list must not be empty. If the list can be empty, call <a href="qlist.html#isEmpty">isEmpty</a>() before calling this function.</p> <p><b>See also </b><a href="qlist.html#removeAt">removeAt</a>() and <a href="qlist.html#takeFirst">takeFirst</a>().</p> <!-- @@@removeFirst --> <!-- $$$removeLast[overload1]$$$removeLast --> <h3 class="fn"><a name="removeLast"></a><span class="type">void</span> QList::<span class="name">removeLast</span> ()</h3> <p>Removes the last item in the list. Calling this function is equivalent to calling removeAt(<a href="qlist.html#size">size</a>() - 1). The list must not be empty. If the list can be empty, call <a href="qlist.html#isEmpty">isEmpty</a>() before calling this function.</p> <p><b>See also </b><a href="qlist.html#removeAt">removeAt</a>() and <a href="qlist.html#takeLast">takeLast</a>().</p> <!-- @@@removeLast --> <!-- $$$removeOne[overload1]$$$removeOneconstT& --> <h3 class="fn"><a name="removeOne"></a><span class="type">bool</span> QList::<span class="name">removeOne</span> ( const <span class="type">T</span> & <i>value</i> )</h3> <p>Removes the first occurrence of <i>value</i> in the list and returns true on success; otherwise returns false.</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type"><a href="qstring.html">QString</a></span><span class="operator">></span> list; list <span class="operator"><</span><span class="operator"><</span> <span class="string">"sun"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"cloud"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"sun"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"rain"</span>; list<span class="operator">.</span>removeOne(<span class="string">"sun"</span>); <span class="comment">// list: ["cloud", ,"sun", "rain"]</span></pre> <p>This function requires the value type to have an implementation of <tt>operator==()</tt>.</p> <p>This function was introduced in Qt 4.4.</p> <p><b>See also </b><a href="qlist.html#removeAll">removeAll</a>(), <a href="qlist.html#removeAt">removeAt</a>(), <a href="qlist.html#takeAt">takeAt</a>(), and <a href="qlist.html#replace">replace</a>().</p> <!-- @@@removeOne --> <!-- $$$replace[overload1]$$$replaceintconstT& --> <h3 class="fn"><a name="replace"></a><span class="type">void</span> QList::<span class="name">replace</span> ( <span class="type">int</span> <i>i</i>, const <span class="type">T</span> & <i>value</i> )</h3> <p>Replaces the item at index position <i>i</i> with <i>value</i>. <i>i</i> must be a valid index position in the list (i.e., 0 <= <i>i</i> < <a href="qlist.html#size">size</a>()).</p> <p><b>See also </b><a href="qlist.html#operator-5b-5d">operator[]</a>() and <a href="qlist.html#removeAt">removeAt</a>().</p> <!-- @@@replace --> <!-- $$$reserve[overload1]$$$reserveint --> <h3 class="fn"><a name="reserve"></a><span class="type">void</span> QList::<span class="name">reserve</span> ( <span class="type">int</span> <i>alloc</i> )</h3> <p>Reserve space for <i>alloc</i> elements.</p> <p>If <i>alloc</i> is smaller than the current size of the list, nothing will happen.</p> <p>Use this function to avoid repetetive reallocation of <a href="qlist.html">QList</a>'s internal data if you can predict how many elements will be appended. Note that the reservation applies only to the internal pointer array.</p> <p>This function was introduced in Qt 4.7.</p> <!-- @@@reserve --> <!-- $$$size[overload1]$$$size --> <h3 class="fn"><a name="size"></a><span class="type">int</span> QList::<span class="name">size</span> () const</h3> <p>Returns the number of items in the list.</p> <p><b>See also </b><a href="qlist.html#isEmpty">isEmpty</a>() and <a href="qlist.html#count">count</a>().</p> <!-- @@@size --> <!-- $$$startsWith[overload1]$$$startsWithconstT& --> <h3 class="fn"><a name="startsWith"></a><span class="type">bool</span> QList::<span class="name">startsWith</span> ( const <span class="type">T</span> & <i>value</i> ) const</h3> <p>Returns true if this list is not empty and its first item is equal to <i>value</i>; otherwise returns false.</p> <p>This function was introduced in Qt 4.5.</p> <p><b>See also </b><a href="qlist.html#isEmpty">isEmpty</a>() and <a href="qlist.html#contains">contains</a>().</p> <!-- @@@startsWith --> <!-- $$$swap[overload1]$$$swapQList<T>& --> <h3 class="fn"><a name="swap"></a><span class="type">void</span> QList::<span class="name">swap</span> ( <span class="type">QList</span><<span class="type">T</span>> & <i>other</i> )</h3> <p>Swaps list <i>other</i> with this list. This operation is very fast and never fails.</p> <p>This function was introduced in Qt 4.8.</p> <!-- @@@swap --> <!-- $$$swap$$$swapintint --> <h3 class="fn"><a name="swap-2"></a><span class="type">void</span> QList::<span class="name">swap</span> ( <span class="type">int</span> <i>i</i>, <span class="type">int</span> <i>j</i> )</h3> <p>Exchange the item at index position <i>i</i> with the item at index position <i>j</i>. This function assumes that both <i>i</i> and <i>j</i> are at least 0 but less than <a href="qlist.html#size">size</a>(). To avoid failure, test that both <i>i</i> and <i>j</i> are at least 0 and less than <a href="qlist.html#size">size</a>().</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type"><a href="qstring.html">QString</a></span><span class="operator">></span> list; list <span class="operator"><</span><span class="operator"><</span> <span class="string">"A"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"B"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"C"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"D"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"E"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"F"</span>; list<span class="operator">.</span><a href="qlist.html#swap">swap</a>(<span class="number">1</span><span class="operator">,</span> <span class="number">4</span>); <span class="comment">// list: ["A", "E", "C", "D", "B", "F"]</span></pre> <p><b>See also </b><a href="qlist.html#move">move</a>().</p> <!-- @@@swap --> <!-- $$$takeAt[overload1]$$$takeAtint --> <h3 class="fn"><a name="takeAt"></a><span class="type">T</span> QList::<span class="name">takeAt</span> ( <span class="type">int</span> <i>i</i> )</h3> <p>Removes the item at index position <i>i</i> and returns it. <i>i</i> must be a valid index position in the list (i.e., 0 <= <i>i</i> < <a href="qlist.html#size">size</a>()).</p> <p>If you don't use the return value, <a href="qlist.html#removeAt">removeAt</a>() is more efficient.</p> <p><b>See also </b><a href="qlist.html#removeAt">removeAt</a>(), <a href="qlist.html#takeFirst">takeFirst</a>(), and <a href="qlist.html#takeLast">takeLast</a>().</p> <!-- @@@takeAt --> <!-- $$$takeFirst[overload1]$$$takeFirst --> <h3 class="fn"><a name="takeFirst"></a><span class="type">T</span> QList::<span class="name">takeFirst</span> ()</h3> <p>Removes the first item in the list and returns it. This is the same as takeAt(0). This function assumes the list is not empty. To avoid failure, call <a href="qlist.html#isEmpty">isEmpty</a>() before calling this function.</p> <p>This operation takes <a href="containers.html#constant-time">constant time</a>.</p> <p>If you don't use the return value, <a href="qlist.html#removeFirst">removeFirst</a>() is more efficient.</p> <p><b>See also </b><a href="qlist.html#takeLast">takeLast</a>(), <a href="qlist.html#takeAt">takeAt</a>(), and <a href="qlist.html#removeFirst">removeFirst</a>().</p> <!-- @@@takeFirst --> <!-- $$$takeLast[overload1]$$$takeLast --> <h3 class="fn"><a name="takeLast"></a><span class="type">T</span> QList::<span class="name">takeLast</span> ()</h3> <p>Removes the last item in the list and returns it. This is the same as takeAt(<a href="qlist.html#size">size</a>() - 1). This function assumes the list is not empty. To avoid failure, call <a href="qlist.html#isEmpty">isEmpty</a>() before calling this function.</p> <p>This operation takes <a href="containers.html#constant-time">constant time</a>.</p> <p>If you don't use the return value, <a href="qlist.html#removeLast">removeLast</a>() is more efficient.</p> <p><b>See also </b><a href="qlist.html#takeFirst">takeFirst</a>(), <a href="qlist.html#takeAt">takeAt</a>(), and <a href="qlist.html#removeLast">removeLast</a>().</p> <!-- @@@takeLast --> <!-- $$$toSet[overload1]$$$toSet --> <h3 class="fn"><a name="toSet"></a><span class="type"><a href="qset.html">QSet</a></span><<span class="type">T</span>> QList::<span class="name">toSet</span> () const</h3> <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> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qstringlist.html">QStringList</a></span> list; list <span class="operator"><</span><span class="operator"><</span> <span class="string">"Julia"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"Mike"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"Mike"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"Julia"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"Julia"</span>; <span class="type"><a href="qset.html">QSet</a></span><span class="operator"><</span><span class="type"><a href="qstring.html">QString</a></span><span class="operator">></span> set <span class="operator">=</span> list<span class="operator">.</span>toSet(); set<span class="operator">.</span><a href="qlist.html#contains">contains</a>(<span class="string">"Julia"</span>); <span class="comment">// returns true</span> set<span class="operator">.</span><a href="qlist.html#contains">contains</a>(<span class="string">"Mike"</span>); <span class="comment">// returns true</span> set<span class="operator">.</span><a href="qlist.html#size">size</a>(); <span class="comment">// returns 2</span></pre> <p><b>See also </b><a href="qlist.html#toVector">toVector</a>(), <a href="qlist.html#fromSet">fromSet</a>(), and <a href="qset.html#fromList">QSet::fromList</a>().</p> <!-- @@@toSet --> <!-- $$$toStdList[overload1]$$$toStdList --> <h3 class="fn"><a name="toStdList"></a><span class="type">std::list</span><<span class="type">T</span>> QList::<span class="name">toStdList</span> () const</h3> <p>Returns a std::list object with the data contained in this <a href="qlist.html">QList</a>. Example:</p> <pre class="cpp"> <span class="type"><a href="qlist.html">QList</a></span><span class="operator"><</span><span class="type">double</span><span class="operator">></span> list; list <span class="operator"><</span><span class="operator"><</span> <span class="number">1.2</span> <span class="operator"><</span><span class="operator"><</span> <span class="number">0.5</span> <span class="operator"><</span><span class="operator"><</span> <span class="number">3.14</span>; std<span class="operator">::</span>list<span class="operator"><</span><span class="type">double</span><span class="operator">></span> stdlist <span class="operator">=</span> list<span class="operator">.</span>toStdList();</pre> <p><b>See also </b><a href="qlist.html#fromStdList">fromStdList</a>() and <a href="qvector.html#toStdVector">QVector::toStdVector</a>().</p> <!-- @@@toStdList --> <!-- $$$toVector[overload1]$$$toVector --> <h3 class="fn"><a name="toVector"></a><span class="type"><a href="qvector.html">QVector</a></span><<span class="type">T</span>> QList::<span class="name">toVector</span> () const</h3> <p>Returns a <a href="qvector.html">QVector</a> object with the data contained in this <a href="qlist.html">QList</a>.</p> <p>Example:</p> <pre class="cpp"> <span class="type"><a href="qstringlist.html">QStringList</a></span> list; list <span class="operator"><</span><span class="operator"><</span> <span class="string">"Sven"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"Kim"</span> <span class="operator"><</span><span class="operator"><</span> <span class="string">"Ola"</span>; <span class="type"><a href="qvector.html">QVector</a></span><span class="operator"><</span><span class="type"><a href="qstring.html">QString</a></span><span class="operator">></span> vect <span class="operator">=</span> list<span class="operator">.</span>toVector(); <span class="comment">// vect: ["Sven", "Kim", "Ola"]</span></pre> <p><b>See also </b><a href="qlist.html#toSet">toSet</a>(), <a href="qlist.html#fromVector">fromVector</a>(), and <a href="qvector.html#fromList">QVector::fromList</a>().</p> <!-- @@@toVector --> <!-- $$$value[overload1]$$$valueint --> <h3 class="fn"><a name="value"></a><span class="type">T</span> QList::<span class="name">value</span> ( <span class="type">int</span> <i>i</i> ) const</h3> <p>Returns the value at index position <i>i</i> in the list.</p> <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> <p><b>See also </b><a href="qlist.html#at">at</a>() and <a href="qlist.html#operator-5b-5d">operator[]</a>().</p> <!-- @@@value --> <!-- $$$value$$$valueintconstT& --> <h3 class="fn"><a name="value-2"></a><span class="type">T</span> QList::<span class="name">value</span> ( <span class="type">int</span> <i>i</i>, const <span class="type">T</span> & <i>defaultValue</i> ) const</h3> <p>This is an overloaded function.</p> <p>If the index <i>i</i> is out of bounds, the function returns <i>defaultValue</i>.</p> <!-- @@@value --> <!-- $$$operator!=[overload1]$$$operator!=constQList<T>& --> <h3 class="fn"><a name="operator-not-eq"></a><span class="type">bool</span> QList::<span class="name">operator!=</span> ( const <span class="type">QList</span><<span class="type">T</span>> & <i>other</i> ) const</h3> <p>Returns true if <i>other</i> is not equal to this list; otherwise returns false.</p> <p>Two lists are considered equal if they contain the same values in the same order.</p> <p>This function requires the value type to have an implementation of <tt>operator==()</tt>.</p> <p><b>See also </b><a href="qlist.html#operator-eq-eq">operator==</a>().</p> <!-- @@@operator!= --> <!-- $$$operator+[overload1]$$$operator+constQList<T>& --> <h3 class="fn"><a name="operator-2b"></a><span class="type">QList</span><<span class="type">T</span>> QList::<span class="name">operator+</span> ( const <span class="type">QList</span><<span class="type">T</span>> & <i>other</i> ) const</h3> <p>Returns a list that contains all the items in this list followed by all the items in the <i>other</i> list.</p> <p><b>See also </b><a href="qlist.html#operator-2b-eq">operator+=</a>().</p> <!-- @@@operator+ --> <!-- $$$operator+=[overload1]$$$operator+=constQList<T>& --> <h3 class="fn"><a name="operator-2b-eq"></a><span class="type">QList</span><<span class="type">T</span>> & QList::<span class="name">operator+=</span> ( const <span class="type">QList</span><<span class="type">T</span>> & <i>other</i> )</h3> <p>Appends the items of the <i>other</i> list to this list and returns a reference to this list.</p> <p><b>See also </b><a href="qlist.html#operator-2b">operator+</a>() and <a href="qlist.html#append">append</a>().</p> <!-- @@@operator+= --> <!-- $$$operator+=$$$operator+=constT& --> <h3 class="fn"><a name="operator-2b-eq-2"></a><span class="type">QList</span><<span class="type">T</span>> & QList::<span class="name">operator+=</span> ( const <span class="type">T</span> & <i>value</i> )</h3> <p>This is an overloaded function.</p> <p>Appends <i>value</i> to the list.</p> <p><b>See also </b><a href="qlist.html#append">append</a>() and <a href="qlist.html#operator-lt-lt">operator<<</a>().</p> <!-- @@@operator+= --> <!-- $$$operator<<[overload1]$$$operator<<constQList<T>& --> <h3 class="fn"><a name="operator-lt-lt"></a><span class="type">QList</span><<span class="type">T</span>> & QList::<span class="name">operator<<</span> ( const <span class="type">QList</span><<span class="type">T</span>> & <i>other</i> )</h3> <p>Appends the items of the <i>other</i> list to this list and returns a reference to this list.</p> <p><b>See also </b><a href="qlist.html#operator-2b-eq">operator+=</a>() and <a href="qlist.html#append">append</a>().</p> <!-- @@@operator<< --> <!-- $$$operator<<$$$operator<<constT& --> <h3 class="fn"><a name="operator-lt-lt-2"></a><span class="type">QList</span><<span class="type">T</span>> & QList::<span class="name">operator<<</span> ( const <span class="type">T</span> & <i>value</i> )</h3> <p>This is an overloaded function.</p> <p>Appends <i>value</i> to the list.</p> <!-- @@@operator<< --> <!-- $$$operator=[overload1]$$$operator=constQList<T>& --> <h3 class="fn"><a name="operator-eq"></a><span class="type">QList</span><<span class="type">T</span>> & QList::<span class="name">operator=</span> ( const <span class="type">QList</span><<span class="type">T</span>> & <i>other</i> )</h3> <p>Assigns <i>other</i> to this list and returns a reference to this list.</p> <!-- @@@operator= --> <!-- $$$operator==[overload1]$$$operator==constQList<T>& --> <h3 class="fn"><a name="operator-eq-eq"></a><span class="type">bool</span> QList::<span class="name">operator==</span> ( const <span class="type">QList</span><<span class="type">T</span>> & <i>other</i> ) const</h3> <p>Returns true if <i>other</i> is equal to this list; otherwise returns false.</p> <p>Two lists are considered equal if they contain the same values in the same order.</p> <p>This function requires the value type to have an implementation of <tt>operator==()</tt>.</p> <p><b>See also </b><a href="qlist.html#operator-not-eq">operator!=</a>().</p> <!-- @@@operator== --> <!-- $$$operator[][overload1]$$$operator[]int --> <h3 class="fn"><a name="operator-5b-5d"></a><span class="type">T</span> & QList::<span class="name">operator[]</span> ( <span class="type">int</span> <i>i</i> )</h3> <p>Returns the item at index position <i>i</i> as a modifiable reference. <i>i</i> must be a valid index position in the list (i.e., 0 <= <i>i</i> < <a href="qlist.html#size">size</a>()).</p> <p>This function is very fast (<a href="containers.html#constant-time">constant time</a>).</p> <p><b>See also </b><a href="qlist.html#at">at</a>() and <a href="qlist.html#value">value</a>().</p> <!-- @@@operator[] --> <!-- $$$operator[]$$$operator[]int --> <h3 class="fn"><a name="operator-5b-5d-2"></a>const <span class="type">T</span> & QList::<span class="name">operator[]</span> ( <span class="type">int</span> <i>i</i> ) const</h3> <p>This is an overloaded function.</p> <p>Same as <a href="qlist.html#at">at</a>().</p> <!-- @@@operator[] --> </div> <div class="relnonmem"> <h2>Related Non-Members</h2> <!-- $$$operator<<$$$operator<<QDataStream&constQList<T>& --> <h3 class="fn"><a name="operator-lt-lt-11"></a><span class="type"><a href="qdatastream.html">QDataStream</a></span> & <span class="name">operator<<</span> ( <span class="type"><a href="qdatastream.html">QDataStream</a></span> & <i>out</i>, const <span class="type">QList</span><<span class="type">T</span>> & <i>list</i> )</h3> <p>Writes the list <i>list</i> to stream <i>out</i>.</p> <p>This function requires the value type to implement <tt>operator<<()</tt>.</p> <p><b>See also </b><a href="datastreamformat.html">Format of the QDataStream operators</a>.</p> <!-- @@@operator<< --> <!-- $$$operator>>$$$operator>>QDataStream&QList<T>& --> <h3 class="fn"><a name="operator-gt-gt-8"></a><span class="type"><a href="qdatastream.html">QDataStream</a></span> & <span class="name">operator>></span> ( <span class="type"><a href="qdatastream.html">QDataStream</a></span> & <i>in</i>, <span class="type">QList</span><<span class="type">T</span>> & <i>list</i> )</h3> <p>Reads a list from stream <i>in</i> into <i>list</i>.</p> <p>This function requires the value type to implement <tt>operator>>()</tt>.</p> <p><b>See also </b><a href="datastreamformat.html">Format of the QDataStream operators</a>.</p> <!-- @@@operator>> --> </div> </div> </div> </div> <div class="ft"> <span></span> </div> </div> <div class="footer"> <p> <acronym title="Copyright">©</acronym> 2013 Digia Plc and/or its subsidiaries. Documentation contributions included herein are the copyrights of their respective owners.</p> <br /> <p> The documentation provided herein is licensed under the terms of the <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation License version 1.3</a> as published by the Free Software Foundation.</p> <p> Documentation sources may be obtained from <a href="http://www.qt-project.org"> www.qt-project.org</a>.</p> <br /> <p> Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. <a title="Privacy Policy" href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p> </div> <script src="scripts/functions.js" type="text/javascript"></script> </body> </html>