QList Class Reference

The QList class is a template class that provides lists.

  1. #include <QList>

Inherited by: QItemSelection, QQueue, QSignalSpy, QStringList, and QTestEventList.

Note: All functions in this class are reentrant.

Detailed Description

The QList class is a template class that provides lists.

QList<T> is one of Qt's generic container classes. It stores a list of values and provides fast index-based access as well as fast insertions and removals.

QList<T>, QLinkedList<T>, and QVector<T> provide similar functionality. Here's an overview:

  • For most purposes, QList is the right class to use. Its index-based API is more convenient than QLinkedList's iterator-based API, and it is usually faster than QVector because of the way it stores its items in memory. It also expands to less code in your executable.
  • If you need a real linked list, with guarantees of constant time insertions in the middle of the list and iterators to items rather than indexes, use QLinkedList.
  • If you want the items to occupy adjacent memory positions, use QVector.

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 shared classes, 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 prepend() and append() are very fast, because QList preallocates memory at both ends of its internal array. (See Algorithmic Complexity 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 QVector a better choice in cases that do lots of appending or inserting, since QVector allocates memory for its items in a single heap allocation.

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 and by the assignment operator, when one list is assigned to another.

Here's an example of a QList that stores integers and a QList that stores QDate values:

  1. QList<int> integerList;
  2. QList<QDate> dateList;

Qt includes a QStringList class that inherits QList<QString> and adds a few convenience functions, such as QStringList::join() and QStringList::find(). (QString::split() creates QStringLists from strings.)

QList stores a list of items. The default constructor creates an empty list. To insert items into the list, you can use operator<<():

  1. QList<QString> list;
  2. list << "one" << "two" << "three";
  3. // list: ["one", "two", "three"]

QList provides these basic functions to add, move, and remove items: insert(), replace(), removeAt(), move(), and swap(). In addition, it provides the following convenience functions: append(), prepend(), removeFirst(), and removeLast().

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:

  1. if (list[0] == "Bob")
  2.     list[0] = "Robert";

Because QList is implemented as an array of pointers, this operation is very fast (constant time). For read-only access, an alternative syntax is to use at():

  1. for (int i = 0; i < list.size(); ++i)  {
  2.     if (list.at(i) == "Jane")
  3.         cout << "Found Jane at position " << i << endl;
  4. }

at() can be faster than operator[](), because it never causes a deep copy to occur.

A common requirement is to remove an item from a list and do something with it. For this, QList provides takeAt(), takeFirst(), and takeLast(). Here's a loop that removes the items from a list one at a time and calls delete on them:

  1. QList<QWidget *> list;
  2. ...
  3. while (!list.isEmpty())
  4.     delete list.takeFirst();

Inserting and removing items at either ends of the list is very fast (constant time 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.

If you want to find all occurrences of a particular value in a list, use indexOf() or lastIndexOf(). 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:

  1. int i = list.indexOf("Jane");
  2. if (i != -1)
  3.     cout << "First occurrence of Jane is at position " << i << endl;

If you simply want to check whether a list contains a particular value, use contains(). If you want to find out how many times a particular value occurs in the list, use count(). If you want to replace all occurrences of a particular value with another, use replace().

QList's value type must be an assignable data type. This covers most data types that are commonly used, but the compiler won't let you, for example, store a QWidget as a value; instead, store a QWidget *. A few functions have additional requirements; for example, indexOf() and lastIndexOf() expect the value type to support operator==(). These requirements are documented on a per-function basis.

Like the other container classes, QList provides Java-style iterators (QListIterator and QMutableListIterator) and STL-style iterators (QList::const_iterator and QList::iterator). 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.

QList does not support inserting, prepending, appending or replacing with references to its own values. Doing so will cause your application to abort with an error message.

To make QList as efficient as possible, its member functions don't validate their input before using it. Except for isEmpty(), member functions always assume the list is not 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 don't define QT_NO_DEBUG, failures will be detected using Q_ASSERT() or Q_ASSERT_X() with an appropriate message.

To avoid failures when your list can be empty, call isEmpty() 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 size() but not less than 0.

See also QListIterator, QMutableListIterator, QLinkedList, and QVector.

Types

Toggle detailstypedef QList ConstIteratorConstIterator

Qt-style synonym for QList::const_iterator.

Look up this member in the source code.

Toggle detailstypedef QList IteratorIterator

Qt-style synonym for QList::iterator.

Look up this member in the source code.

Toggle detailstypedef QList const_pointerconst_pointer

Typedef for const T *. Provided for STL compatibility.

Look up this member in the source code.

Toggle detailstypedef QList const_referenceconst_reference

Typedef for const T &. Provided for STL compatibility.

Look up this member in the source code.

Toggle detailstypedef QList difference_typedifference_type

Typedef for ptrdiff_t. Provided for STL compatibility.

Look up this member in the source code.

Toggle detailstypedef QList pointerpointer

Typedef for T *. Provided for STL compatibility.

Look up this member in the source code.

Toggle detailstypedef QList referencereference

Typedef for T &. Provided for STL compatibility.

Look up this member in the source code.

Toggle detailstypedef QList size_typesize_type

Typedef for int. Provided for STL compatibility.

Look up this member in the source code.

Toggle detailstypedef QList value_typevalue_type

Typedef for T. Provided for STL compatibility.

Look up this member in the source code.

    Public Functions

    Toggle details QList

    QListQList () ()

    Constructs an empty list.

    Look up this member in the source code.

    Toggle details QList

    QListQList ( const QList<T> &other ) ( const QList<T> &other )

    Constructs a copy of other.

    This operation takes constant time, because QList is implicitly shared. This makes returning a QList from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes linear time.

    See also operator=().

    Look up this member in the source code.

    Toggle details QList

    ~QList~QList () ()

    Destroys the list. References to the values in the list and all iterators of this list become invalid.

    Look up this member in the source code.

    Toggle details void QList

    appendappend ( const T &value ) ( const T &value )

    Inserts value at the end of the list.

    Example:

    1.                     QList<QString> list;
    2. list.append("one");
    3. list.append("two");
    4. list.append("three");
    5. // list: ["one", "two", "three"]

    This is the same as list.insert(size(), value).

    This operation is typically very fast (constant time), because QList preallocates extra space on both sides of its internal buffer to allow for fast growth at both ends of the list.

    See also operator<<(), prepend(), and insert().

    Look up this member in the source code.

    Toggle details void QList

    appendappend ( const QList<T> &value ) ( const QList<T> &value )

    This is an overloaded function.

    Appends the items of the value list to this list.

    See also operator<<() and operator+=().

    Look up this member in the source code.

    Toggle details const T & QList

    atat ( int i ) ( int i )const

    Returns the item at index position i in the list. i must be a valid index position in the list (i.e., 0 <= i < size()).

    This function is very fast (constant time).

    See also value() and operator[]().

    Look up this member in the source code.

    Toggle details T & QList

    backback () ()

    This function is provided for STL compatibility. It is equivalent to last(). The list must not be empty. If the list can be empty, call isEmpty() before calling this function.

    Look up this member in the source code.

    Toggle details const T & QList

    backback () ()const

    This is an overloaded function.

    Look up this member in the source code.

    Toggle details iterator QList

    beginbegin () ()

    Returns an STL-style iterator pointing to the first item in the list.

    See also constBegin() and end().

    Look up this member in the source code.

    Toggle details const_iterator QList

    beginbegin () ()const

    This is an overloaded function.

    Look up this member in the source code.

    Toggle details void QList

    clearclear () ()

    Removes all items from the list.

    See also removeAll().

    Look up this member in the source code.

    Toggle details const_iterator QList

    constBeginconstBegin () ()const

    Returns a const STL-style iterator pointing to the first item in the list.

    See also begin() and constEnd().

    Look up this member in the source code.

    Toggle details const_iterator QList

    constEndconstEnd () ()const

    Returns a const STL-style iterator pointing to the imaginary item after the last item in the list.

    See also constBegin() and end().

    Look up this member in the source code.

    Toggle details bool QList

    containscontains ( const T &value ) ( const T &value )const

    Returns true if the list contains an occurrence of value; otherwise returns false.

    This function requires the value type to have an implementation of operator==().

    See also indexOf() and count().

    Look up this member in the source code.

    Toggle details int QList

    countcount ( const T &value ) ( const T &value )const

    Returns the number of occurrences of value in the list.

    This function requires the value type to have an implementation of operator==().

    See also contains() and indexOf().

    Look up this member in the source code.

    Toggle details int QList

    countcount () ()const

    Returns the number of items in the list. This is effectively the same as size().

    Look up this member in the source code.

    Toggle details bool QList

    emptyempty () ()const

    This function is provided for STL compatibility. It is equivalent to isEmpty() and returns true if the list is empty.

    Look up this member in the source code.

    Toggle details iterator QList

    endend () ()

    Returns an STL-style iterator pointing to the imaginary item after the last item in the list.

    See also begin() and constEnd().

    Look up this member in the source code.

    Toggle details const_iterator QList

    endend () ()const

    This is an overloaded function.

    Look up this member in the source code.

    Toggle details bool QList

    endsWithendsWith ( const T &value ) ( const T &value )const

    Returns true if this list is not empty and its last item is equal to value; otherwise returns false.

    See also isEmpty() and contains().

    Look up this member in the source code.

    Toggle details iterator QList

    eraseerase ( iterator pos ) ( iterator pos )

    Removes the item associated with the iterator pos from the list, and returns an iterator to the next item in the list (which may be end()).

    See also insert() and removeAt().

    Look up this member in the source code.

    Toggle details iterator QList

    eraseerase ( iterator begin , iterator end ) ( iterator begin , iterator end )

    This is an overloaded function.

    Removes all the items from begin up to (but not including) end. Returns an iterator to the same item that end referred to before the call.

    Look up this member in the source code.

    Toggle details T & QList

    firstfirst () ()

    Returns a reference to the first item in the list. The list must not be empty. If the list can be empty, call isEmpty() before calling this function.

    See also last() and isEmpty().

    Look up this member in the source code.

    Toggle details const T & QList

    firstfirst () ()const

    This is an overloaded function.

    Look up this member in the source code.

    Toggle details QList<T> QList

    fromSetfromSet ( const QSet <T> &set ) ( const QSet <T> &set ) [static]

    Returns a QList object with the data contained in set. The order of the elements in the QList is undefined.

    Example:

    1.                     QSet<int> set;
    2. set << 20 << 30 << 40 << ... << 70;
    3.  
    4. QList<int> list = QList<int>::fromSet(set);
    5. qSort(list);

    See also fromVector(), toSet(), QSet::toList(), and qSort().

    Look up this member in the source code.

    Toggle details QList<T> QList

    fromStdListfromStdList ( const std::list<T> &list ) ( const std::list<T> &list ) [static]

    Returns a QList object with the data contained in list. The order of the elements in the QList is the same as in list.

    Example:

    1. std::list<double> stdlist;
    2. list.push_back(1.2);
    3. list.push_back(0.5);
    4. list.push_back(3.14);
    5.  
    6. QList<double> list = QList<double>::fromStdList(stdlist);

    See also toStdList() and QVector::fromStdVector().

    Look up this member in the source code.

    Toggle details QList<T> QList

    fromVectorfromVector ( const QVector <T> &vector ) ( const QVector <T> &vector ) [static]

    Returns a QList object with the data contained in vector.

    Example:

    1.                     QVector<double> vect;
    2. vect << 20.0 << 30.0 << 40.0 << 50.0;
    3.  
    4. QList<double> list = QVector<T>::fromVector(vect);
    5. // list: [20.0, 30.0, 40.0, 50.0]

    See also fromSet(), toVector(), and QVector::toList().

    Look up this member in the source code.

    Toggle details T & QList

    frontfront () ()

    This function is provided for STL compatibility. It is equivalent to first(). The list must not be empty. If the list can be empty, call isEmpty() before calling this function.

    Look up this member in the source code.

    Toggle details const T & QList

    frontfront () ()const

    This is an overloaded function.

    Look up this member in the source code.

    Toggle details int QList

    indexOfindexOf ( const T &value , int from=0 ) ( const T &value , int from=0 )const

    Returns the index position of the first occurrence of value in the list, searching forward from index position from. Returns -1 if no item matched.

    Example:

    1.                     QList<QString> list;
    2. list << "A" << "B" << "C" << "B" << "A";
    3. list.indexOf("B");          // returns 1
    4. list.indexOf("B", 1);       // returns 1
    5. list.indexOf("B", 2);       // returns 3
    6. list.indexOf("X");          // returns -1

    This function requires the value type to have an implementation of operator==().

    Note that QList uses 0-based indexes, just like C++ arrays. Negative indexes are not supported with the exception of the value mentioned above.

    See also lastIndexOf() and contains().

    Look up this member in the source code.

    Toggle details void QList

    insertinsert ( int i , const T &value ) ( int i , const T &value )

    Inserts value at index position i in the list. If i is 0, the value is prepended to the list. If i is size(), the value is appended to the list.

    Example:

    1.                     QList<QString> list;
    2. list << "alpha" << "beta" << "delta";
    3. list.insert(2, "gamma");
    4. // list: ["alpha", "beta", "gamma", "delta"]

    See also append(), prepend(), replace(), and removeAt().

    Look up this member in the source code.

    Toggle details iterator QList

    insertinsert ( iterator before , const T &value ) ( iterator before , const T &value )

    This is an overloaded function.

    Inserts value in front of the item pointed to by the iterator before. 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.

    Look up this member in the source code.

    Toggle details bool QList

    isEmptyisEmpty () ()const

    Returns true if the list contains no items; otherwise returns false.

    See also size().

    Look up this member in the source code.

    Toggle details T & QList

    lastlast () ()

    Returns a reference to the last item in the list. The list must not be empty. If the list can be empty, call isEmpty() before calling this function.

    See also first() and isEmpty().

    Look up this member in the source code.

    Toggle details const T & QList

    lastlast () ()const

    This is an overloaded function.

    Look up this member in the source code.

    Toggle details int QList

    lastIndexOflastIndexOf ( const T &value , int from=-1 ) ( const T &value , int from=-1 )const

    Returns the index position of the last occurrence of value in the list, searching backward from index position from. If from is -1 (the default), the search starts at the last item. Returns -1 if no item matched.

    Example:

    1.                     QList<QString> list;
    2. list << "A" << "B" << "C" << "B" << "A";
    3. list.lastIndexOf("B");      // returns 3
    4. list.lastIndexOf("B", 3);   // returns 3
    5. list.lastIndexOf("B", 2);   // returns 1
    6. list.lastIndexOf("X");      // returns -1

    This function requires the value type to have an implementation of operator==().

    Note that QList uses 0-based indexes, just like C++ arrays. Negative indexes are not supported with the exception of the value mentioned above.

    See also indexOf().

    Look up this member in the source code.

    Toggle details int QList

    lengthlength () ()const

    This function is identical to count().

    See also count().

    Look up this member in the source code.

    Toggle details QList<T> QList

    midmid ( int pos , int length=-1 ) ( int pos , int length=-1 )const

    Returns a list whose elements are copied from this list, starting at position pos. If length is -1 (the default), all elements from pos are copied; otherwise length elements (or all remaining elements if there are less than length elements) are copied.

    Look up this member in the source code.

    Toggle details void QList

    movemove ( int from , int to ) ( int from , int to )

    Moves the item at index position from to index position to.

    Example:

    1.                     QList<QString> list;
    2. list << "A" << "B" << "C" << "D" << "E" << "F";
    3. list.move(1, 4);
    4. // list: ["A", "C", "D", "E", "B", "F"]

    This is the same as insert(to, takeAt(from)).This function assumes that both from and to are at least 0 but less than size(). To avoid failure, test that both from and to are at least 0 and less than size().

    See also swap(), insert(), and takeAt().

    Look up this member in the source code.

    Toggle details void QList

    pop_backpop_back () ()

    This function is provided for STL compatibility. It is equivalent to removeLast(). The list must not be empty. If the list can be empty, call isEmpty() before calling this function.

    Look up this member in the source code.

    Toggle details void QList

    pop_frontpop_front () ()

    This function is provided for STL compatibility. It is equivalent to removeFirst(). The list must not be empty. If the list can be empty, call isEmpty() before calling this function.

    Look up this member in the source code.

    Toggle details void QList

    prependprepend ( const T &value ) ( const T &value )

    Inserts value at the beginning of the list.

    Example:

    1.                     QList<QString> list;
    2. list.prepend("one");
    3. list.prepend("two");
    4. list.prepend("three");
    5. // list: ["three", "two", "one"]

    This is the same as list.insert(0, value).

    This operation is usually very fast (constant time), because QList preallocates extra space on both sides of its internal buffer to allow for fast growth at both ends of the list.

    See also append() and insert().

    Look up this member in the source code.

    Toggle details void QList

    push_backpush_back ( const T &value ) ( const T &value )

    This function is provided for STL compatibility. It is equivalent to append(value).

    Look up this member in the source code.

    Toggle details void QList

    push_frontpush_front ( const T &value ) ( const T &value )

    This function is provided for STL compatibility. It is equivalent to prepend(value).

    Look up this member in the source code.

    Toggle details int QList

    removeAllremoveAll ( const T &value ) ( const T &value )

    Removes all occurrences of value in the list and returns the number of entries removed.

    Example:

    1.                     QList<QString> list;
    2. list << "sun" << "cloud" << "sun" << "rain";
    3. list.removeAll("sun");
    4. // list: ["cloud", "rain"]

    This function requires the value type to have an implementation of operator==().

    See also removeOne(), removeAt(), takeAt(), and replace().

    Look up this member in the source code.

    Toggle details void QList

    removeAtremoveAt ( int i ) ( int i )

    Removes the item at index position i. i must be a valid index position in the list (i.e., 0 <= i < size()).

    See also takeAt(), removeFirst(), removeLast(), and removeOne().

    Look up this member in the source code.

    Toggle details void QList

    removeFirstremoveFirst () ()

    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 isEmpty() before calling this function.

    See also removeAt() and takeFirst().

    Look up this member in the source code.

    Toggle details void QList

    removeLastremoveLast () ()

    Removes the last item in the list. Calling this function is equivalent to calling removeAt(size() - 1). The list must not be empty. If the list can be empty, call isEmpty() before calling this function.

    See also removeAt() and takeLast().

    Look up this member in the source code.

    Toggle details bool QList

    removeOneremoveOne ( const T &value ) ( const T &value )

    Removes the first occurrence of value in the list and returns true on success; otherwise returns false.

    Example:

    1.                     QList<QString> list;
    2. list << "sun" << "cloud" << "sun" << "rain";
    3. list.removeOne("sun");
    4. // list: ["cloud", ,"sun", "rain"]

    This function requires the value type to have an implementation of operator==().

    See also removeAll(), removeAt(), takeAt(), and replace().

    Look up this member in the source code.

    Toggle details void QList

    replacereplace ( int i , const T &value ) ( int i , const T &value )

    Replaces the item at index position i with value. i must be a valid index position in the list (i.e., 0 <= i < size()).

    See also operator[]() and removeAt().

    Look up this member in the source code.

    Toggle details void QList

    reservereserve ( int alloc ) ( int alloc )

    Reserve space for alloc elements.

    If alloc is smaller than the current size of the list, nothing will happen.

    Use this function to avoid repetetive reallocation of QList's internal data if you can predict how many elements will be appended. Note that the reservation applies only to the internal pointer array.

    Look up this member in the source code.

    Toggle details int QList

    sizesize () ()const

    Returns the number of items in the list.

    See also isEmpty() and count().

    Look up this member in the source code.

    Toggle details bool QList

    startsWithstartsWith ( const T &value ) ( const T &value )const

    Returns true if this list is not empty and its first item is equal to value; otherwise returns false.

    See also isEmpty() and contains().

    Look up this member in the source code.

    Toggle details void QList

    swapswap ( int i , int j ) ( int i , int j )

    Exchange the item at index position i with the item at index position j. This function assumes that both i and j are at least 0 but less than size(). To avoid failure, test that both i and j are at least 0 and less than size().

    Example:

    1.                     QList<QString> list;
    2. list << "A" << "B" << "C" << "D" << "E" << "F";
    3. list.swap(1, 4);
    4. // list: ["A", "E", "C", "D", "B", "F"]

    See also move().

    Look up this member in the source code.

    Toggle details T QList

    takeAttakeAt ( int i ) ( int i )

    Removes the item at index position i and returns it. i must be a valid index position in the list (i.e., 0 <= i < size()).

    If you don't use the return value, removeAt() is more efficient.

    See also removeAt(), takeFirst(), and takeLast().

    Look up this member in the source code.

    Toggle details T QList

    takeFirsttakeFirst () ()

    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 isEmpty() before calling this function.

    This operation takes constant time.

    If you don't use the return value, removeFirst() is more efficient.

    See also takeLast(), takeAt(), and removeFirst().

    Look up this member in the source code.

    Toggle details T QList

    takeLasttakeLast () ()

    Removes the last item in the list and returns it. This is the same as takeAt(size() - 1). This function assumes the list is not empty. To avoid failure, call isEmpty() before calling this function.

    This operation takes constant time.

    If you don't use the return value, removeLast() is more efficient.

    See also takeFirst(), takeAt(), and removeLast().

    Look up this member in the source code.

    Toggle details QSet <T> QList

    toSettoSet () ()const

    Returns a QSet object with the data contained in this QList. Since QSet doesn't allow duplicates, the resulting QSet might be smaller than the original list was.

    Example:

    1.                     QStringList list;
    2. list << "Julia" << "Mike" << "Mike" << "Julia" << "Julia";
    3.  
    4. QSet<QString> set = list.toSet();
    5. set.contains("Julia");  // returns true
    6. set.contains("Mike");   // returns true
    7. set.size();             // returns 2

    See also toVector(), fromSet(), and QSet::fromList().

    Look up this member in the source code.

    Toggle details std::list<T> QList

    toStdListtoStdList () ()const

    Returns a std::list object with the data contained in this QList. Example:

    1.                     QList<double> list;
    2. list << 1.2 << 0.5 << 3.14;
    3.  
    4. std::list<double> stdlist = list.toStdList();

    See also fromStdList() and QVector::toStdVector().

    Look up this member in the source code.

    Toggle details QVector <T> QList

    toVectortoVector () ()const

    Returns a QVector object with the data contained in this QList.

    Example:

    1.                     QStringList list;
    2. list << "Sven" << "Kim" << "Ola";
    3.  
    4. QVector<QString> vect = list.toVector();
    5. // vect: ["Sven", "Kim", "Ola"]

    See also toSet(), fromVector(), and QVector::fromList().

    Look up this member in the source code.

    Toggle details T QList

    valuevalue ( int i ) ( int i )const

    Returns the value at index position i in the list.

    If the index i is out of bounds, the function returns a default-constructed value. If you are certain that the index is going to be within bounds, you can use at() instead, which is slightly faster.

    See also at() and operator[]().

    Look up this member in the source code.

    Toggle details T QList

    valuevalue ( int i , const T &defaultValue ) ( int i , const T &defaultValue )const

    This is an overloaded function.

    If the index i is out of bounds, the function returns defaultValue.

    Look up this member in the source code.

    Toggle details bool QList

    operator!=operator!= ( const QList<T> &other ) ( const QList<T> &other )const

    Returns true if other is not equal to this list; otherwise returns false.

    Two lists are considered equal if they contain the same values in the same order.

    This function requires the value type to have an implementation of operator==().

    See also operator==().

    Look up this member in the source code.

    Toggle details QList<T> QList

    operator+operator+ ( const QList<T> &other ) ( const QList<T> &other )const

    Returns a list that contains all the items in this list followed by all the items in the other list.

    See also operator+=().

    Look up this member in the source code.

    Toggle details QList<T> & QList

    operator+=operator+= ( const QList<T> &other ) ( const QList<T> &other )

    Appends the items of the other list to this list and returns a reference to this list.

    See also operator+() and append().

    Look up this member in the source code.

    Toggle details QList<T> & QList

    operator+=operator+= ( const T &value ) ( const T &value )

    This is an overloaded function.

    Appends value to the list.

    See also append() and operator<<().

    Look up this member in the source code.

    Toggle details QList<T> & QList

    operator<<operator<< ( const QList<T> &other ) ( const QList<T> &other )

    Appends the items of the other list to this list and returns a reference to this list.

    See also operator+=() and append().

    Look up this member in the source code.

    Toggle details QList<T> & QList

    operator<<operator<< ( const T &value ) ( const T &value )

    This is an overloaded function.

    Appends value to the list.

    Look up this member in the source code.

    Toggle details QList<T> & QList

    operator=operator= ( const QList<T> &other ) ( const QList<T> &other )

    Assigns other to this list and returns a reference to this list.

    Look up this member in the source code.

    Toggle details bool QList

    operator==operator== ( const QList<T> &other ) ( const QList<T> &other )const

    Returns true if other is equal to this list; otherwise returns false.

    Two lists are considered equal if they contain the same values in the same order.

    This function requires the value type to have an implementation of operator==().

    See also operator!=().

    Look up this member in the source code.

    Toggle details T & QList

    operator[]operator[] ( int i ) ( int i )

    Returns the item at index position i as a modifiable reference. i must be a valid index position in the list (i.e., 0 <= i < size()).

    This function is very fast (constant time).

    See also at() and value().

    Look up this member in the source code.

    Toggle details const T & QList

    operator[]operator[] ( int i ) ( int i )const

    This is an overloaded function.

    Same as at().

    Look up this member in the source code.

    Toggle details iterator QList

    findfind ( const T &t ) ( const T &t ) Qt3-support

    Use indexOf() instead.

    Look up this member in the source code.

    Toggle details const_iterator QList

    findfind ( const T &t ) ( const T &t )const Qt3-support

    Use indexOf() instead.

    Look up this member in the source code.

    Toggle details iterator QList

    findfind ( iterator from , const T &t ) ( iterator from , const T &t ) Qt3-support

    Use indexOf() instead.

    Look up this member in the source code.

    Toggle details const_iterator QList

    findfind ( const_iterator from , const T &t ...) ( const_iterator from , const T &t )const Qt3-support

    Use indexOf() instead.

    Look up this member in the source code.

    Toggle details int QList

    findIndexfindIndex ( const T &t ) ( const T &t )const Qt3-support

    Use indexOf() instead.

    Look up this member in the source code.

    Toggle details iterator QList

    removeremove ( iterator pos ) ( iterator pos ) Qt3-support

    Use erase() instead.

    Look up this member in the source code.

    Toggle details int QList

    removeremove ( const T &t ) ( const T &t ) Qt3-support

    Use removeAll() instead.

    Look up this member in the source code.

    Notes provided by the Qt Community
    Informative
    • 5

    Votes: 4

    Coverage: Qt library 4.8, 4.7, 5.0

    Picture of Volker Volker

    Ant Farmer
    35 notes

    Nokia Certified Qt Developer

    Regarding QList::insert ( int i, const T & value )

    The documentation states:

    Inserts value at index position i in the list. If i is 0, the value is prepended to the list. If i is size(), the value is appended to the list.

    Actually, the behavior is a bit more relaxed:

    • if i is negative or zero, the value is prepended to the list
    • if i is equal to size() or bigger, the value is appended to the list

    [Revisions]

    Informative
    • 5

    Votes: 1

    Coverage: Qt library 4.7, 4.8, 5.0

    Picture of Asperamanca Asperamanca

    Robot Herder
    4 notes

    Inheriting from QList

    When writing a class that inherits from QList, be aware that QList’s destructor is non-virtual. Therefore, the destructor of your derived class may not be called when a pointer to the base class QList is used.

    If you need to add actual code to your derived class destructor, you must somehow make sure no-one ever uses a base class pointer referring to your derived class.

    My personal view is that this would create a potential source of trouble, and should be avoided altogether.

    [Revisions]