1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
14 | ** written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Free Documentation License
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
20 | ** file.
|
---|
21 | **
|
---|
22 | ** If you have questions regarding the use of this file, please contact
|
---|
23 | ** Nokia at [email protected].
|
---|
24 | ** $QT_END_LICENSE$
|
---|
25 | **
|
---|
26 | ****************************************************************************/
|
---|
27 |
|
---|
28 | /*!
|
---|
29 | \group tools
|
---|
30 | \title Non-GUI Classes
|
---|
31 | \ingroup groups
|
---|
32 |
|
---|
33 | \brief Collection classes such as list, queue, stack and string, along
|
---|
34 | with other classes that can be used without needing QApplication.
|
---|
35 |
|
---|
36 | The non-GUI classes are general-purpose collection and string classes
|
---|
37 | that may be used independently of the GUI classes.
|
---|
38 |
|
---|
39 | In particular, these classes do not depend on QApplication at all,
|
---|
40 | and so can be used in non-GUI programs.
|
---|
41 |
|
---|
42 | */
|
---|
43 |
|
---|
44 | /*!
|
---|
45 | \page containers.html
|
---|
46 | \title Container Classes
|
---|
47 | \ingroup technology-apis
|
---|
48 | \ingroup groups
|
---|
49 | \ingroup qt-basic-concepts
|
---|
50 | \keyword container class
|
---|
51 | \keyword container classes
|
---|
52 |
|
---|
53 | \brief Qt's template-based container classes.
|
---|
54 |
|
---|
55 | \tableofcontents
|
---|
56 |
|
---|
57 | \section1 Introduction
|
---|
58 |
|
---|
59 | The Qt library provides a set of general purpose template-based
|
---|
60 | container classes. These classes can be used to store items of a
|
---|
61 | specified type. For example, if you need a resizable array of
|
---|
62 | \l{QString}s, use QVector<QString>.
|
---|
63 |
|
---|
64 | These container classes are designed to be lighter, safer, and
|
---|
65 | easier to use than the STL containers. If you are unfamiliar with
|
---|
66 | the STL, or prefer to do things the "Qt way", you can use these
|
---|
67 | classes instead of the STL classes.
|
---|
68 |
|
---|
69 | The container classes are \l{implicitly shared}, they are
|
---|
70 | \l{reentrant}, and they are optimized for speed, low memory
|
---|
71 | consumption, and minimal inline code expansion, resulting in
|
---|
72 | smaller executables. In addition, they are \l{thread-safe}
|
---|
73 | in situations where they are used as read-only containers
|
---|
74 | by all threads used to access them.
|
---|
75 |
|
---|
76 | For traversing the items stored in a container, you can use one
|
---|
77 | of two types of iterators: \l{Java-style iterators} and
|
---|
78 | \l{STL-style iterators}. The Java-style iterators are easier to
|
---|
79 | use and provide high-level functionality, whereas the STL-style
|
---|
80 | iterators are slightly more efficient and can be used together
|
---|
81 | with Qt's and STL's \l{generic algorithms}.
|
---|
82 |
|
---|
83 | Qt also offers a \l{foreach} keyword that make it very
|
---|
84 | easy to iterate over all the items stored in a container.
|
---|
85 |
|
---|
86 | \section1 The Container Classes
|
---|
87 |
|
---|
88 | Qt provides the following sequential containers: QList,
|
---|
89 | QLinkedList, QVector, QStack, and QQueue. For most
|
---|
90 | applications, QList is the best type to use. Although it is
|
---|
91 | implemented as an array-list, it provides very fast prepends and
|
---|
92 | appends. If you really need a linked-list, use QLinkedList; if you
|
---|
93 | want your items to occupy consecutive memory locations, use QVector.
|
---|
94 | QStack and QQueue are convenience classes that provide LIFO and
|
---|
95 | FIFO semantics.
|
---|
96 |
|
---|
97 | Qt also provides these associative containers: QMap,
|
---|
98 | QMultiMap, QHash, QMultiHash, and QSet. The "Multi" containers
|
---|
99 | conveniently support multiple values associated with a single
|
---|
100 | key. The "Hash" containers provide faster lookup by using a hash
|
---|
101 | function instead of a binary search on a sorted set.
|
---|
102 |
|
---|
103 | As special cases, the QCache and QContiguousCache classes provide
|
---|
104 | efficient hash-lookup of objects in a limited cache storage.
|
---|
105 |
|
---|
106 | \table
|
---|
107 | \header \o Class \o Summary
|
---|
108 |
|
---|
109 | \row \o \l{QList}<T>
|
---|
110 | \o This is by far the most commonly used container class. It
|
---|
111 | stores a list of values of a given type (T) that can be accessed
|
---|
112 | by index. Internally, the QList is implemented using an array,
|
---|
113 | ensuring that index-based access is very fast.
|
---|
114 |
|
---|
115 | Items can be added at either end of the list using
|
---|
116 | QList::append() and QList::prepend(), or they can be inserted in
|
---|
117 | the middle using QList::insert(). More than any other container
|
---|
118 | class, QList is highly optimized to expand to as little code as
|
---|
119 | possible in the executable. QStringList inherits from
|
---|
120 | QList<QString>.
|
---|
121 |
|
---|
122 | \row \o \l{QLinkedList}<T>
|
---|
123 | \o This is similar to QList, except that it uses
|
---|
|
---|