QLinkedList Class

Detailed Description

QLinkedList<T> is one of Qt's generic container classes. It stores a list of values and provides iterator-based access as well as constant time 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 (see Algorithmic Complexity for details). 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.

Here's an example of a QLinkedList that stores integers and a QLinkedList that stores QTime values:

 
Sélectionnez
QLinkedList&lt;int&gt; integerList;
QLinkedList&lt;QTime&gt; timeList;

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

 
Sélectionnez
QLinkedList&lt;QString&gt; list;
list &lt;&lt; "one" &lt;&lt; "two" &lt;&lt; "three";
// list: ["one", "two", "three"]

If you want to get the first or last item in a linked list, use first() or last(). If you want to remove an item from either end of the list, use