Use QList instead of QVector in corelib docs

Task-number: QTBUG-84469
Task-number: QTBUG-85221
Change-Id: Ieb0ba7d82409e3c053a5788a01e92ea495505643
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
This commit is contained in:
Jarek Kobus 2020-06-26 12:17:38 +02:00
parent f3c7d22dd0
commit c70c4e4266
16 changed files with 347 additions and 863 deletions

View File

@ -205,7 +205,7 @@ for (i = splitter->sizes().begin();
//! [15] //! [15]
QVector<QString> values; QList<QString> values;
... ...
QString str; QString str;
foreach (str, values) foreach (str, values)
@ -214,16 +214,16 @@ foreach (str, values)
//! [16] //! [16]
QVector<QString> values; QList<QString> values;
... ...
QVectorIterator<QString> i(values); QListIterator<QString> i(values);
while (i.hasNext()) while (i.hasNext())
qDebug() << i.next(); qDebug() << i.next();
//! [16] //! [16]
//! [17] //! [17]
QVector<QString> values; QList<QString> values;
... ...
foreach (const QString &str, values) foreach (const QString &str, values)
qDebug() << str; qDebug() << str;
@ -231,7 +231,7 @@ foreach (const QString &str, values)
//! [18] //! [18]
QVector<QString> values; QList<QString> values;
... ...
foreach (const QString &str, values) { foreach (const QString &str, values) {
if (str.isEmpty()) if (str.isEmpty())
@ -284,10 +284,10 @@ QString onlyLetters(const QString &in)
//! [23] //! [23]
//! [24] //! [24]
QVector<int> a, b; QList<int> a, b;
a.resize(100000); // make a big vector filled with 0. a.resize(100000); // make a big list filled with 0.
QVector<int>::iterator i = a.begin(); QList<int>::iterator i = a.begin();
// WRONG way of using the iterator i: // WRONG way of using the iterator i:
b = a; b = a;
/* /*
@ -309,13 +309,13 @@ int j = *i; // Undefined behavior!
/* /*
The data from b (which i pointed to) is gone. The data from b (which i pointed to) is gone.
This would be well-defined with STL containers (and (*i) == 5), This would be well-defined with STL containers (and (*i) == 5),
but with QVector this is likely to crash. but with QList this is likely to crash.
*/ */
//! [24] //! [24]
//! [25] //! [25]
QVector<int> vector{1, 2, 3, 4, 4, 5}; QList<int> list { 1, 2, 3, 4, 4, 5 };
QSet<int> set(vector.begin(), vector.end()); QSet<int> set(list.begin(), list.end());
/* /*
Will generate a QSet containing 1, 2, 4, 5. Will generate a QSet containing 1, 2, 4, 5.
*/ */

View File

@ -105,13 +105,13 @@ QChar resolveEntity(const QString &entity)
QStringList list; QStringList list;
list << "one" << "two" << "three"; list << "one" << "two" << "three";
QVector<QString> vect1(3); QList<QString> list1(3);
qCopy(list.begin(), list.end(), vect1.begin()); qCopy(list.begin(), list.end(), list1.begin());
// vect: [ "one", "two", "three" ] // list1: [ "one", "two", "three" ]
QVector<QString> vect2(8); QList<QString> list2(8);
qCopy(list.begin(), list.end(), vect2.begin() + 2); qCopy(list.begin(), list.end(), list2.begin() + 2);
// vect: [ "", "", "one", "two", "three", "", "", "" ] // list2: [ "", "", "one", "two", "three", "", "", "" ]
//! [4] //! [4]
@ -119,26 +119,26 @@ qCopy(list.begin(), list.end(), vect2.begin() + 2);
QStringList list; QStringList list;
list << "one" << "two" << "three"; list << "one" << "two" << "three";
QVector<QString> vect(5); QList<QString> backList(5);
qCopyBackward(list.begin(), list.end(), vect.end()); qCopyBackward(list.begin(), list.end(), backList.end());
// vect: [ "", "", "one", "two", "three" ] // backList: [ "", "", "one", "two", "three" ]
//! [5] //! [5]
//! [6] //! [6]
QStringList list; QStringList listLeft;
list << "one" << "two" << "three"; listLeft << "one" << "two" << "three";
QVector<QString> vect(3); QList<QString> listRight(3);
vect[0] = "one"; listRight[0] = "one";
vect[1] = "two"; listRight[1] = "two";
vect[2] = "three"; listRight[2] = "three";
bool ret1 = qEqual(list.begin(), list.end(), vect.begin()); bool ret1 = qEqual(listLeft.begin(), listLeft.end(), listRight.begin());
// ret1 == true // ret1 == true
vect[2] = "seven"; listRight[2] = "seven";
bool ret2 = qEqual(list.begin(), list.end(), vect.begin()); bool ret2 = qEqual(listLeft.begin(), listLeft.end(), listRight.begin());
// ret2 == false // ret2 == false
//! [6] //! [6]
@ -281,19 +281,19 @@ list.insert(i, 12);
//! [19] //! [19]
QVector<int> vect; QList<int> list;
vect << 3 << 3 << 6 << 6 << 6 << 8; list << 3 << 3 << 6 << 6 << 6 << 8;
QVector<int>::iterator begin6 = QList<int>::iterator begin6 =
qLowerBound(vect.begin(), vect.end(), 6); qLowerBound(list.begin(), list.end(), 6);
QVector<int>::iterator end6 = QList<int>::iterator end6 =
qUpperBound(begin6, vect.end(), 6); qUpperBound(begin6, list.end(), 6);
QVector<int>::iterator i = begin6; QList<int>::iterator i = begin6;
while (i != end6) { while (i != end6) {
*i = 7; *i = 7;
++i; ++i;
} }
// vect: [ 3, 3, 7, 7, 7, 8 ] // list: [ 3, 3, 7, 7, 7, 8 ]
//! [19] //! [19]
@ -312,29 +312,29 @@ list.insert(i, 12);
//! [21] //! [21]
QVector<int> vect; QList<int> list;
vect << 3 << 3 << 6 << 6 << 6 << 8; list << 3 << 3 << 6 << 6 << 6 << 8;
QVector<int>::iterator begin6 = QList<int>::iterator begin6 =
qLowerBound(vect.begin(), vect.end(), 6); qLowerBound(list.begin(), list.end(), 6);
QVector<int>::iterator end6 = QList<int>::iterator end6 =
qUpperBound(vect.begin(), vect.end(), 6); qUpperBound(list.begin(), list.end(), 6);
QVector<int>::iterator i = begin6; QList<int>::iterator i = begin6;
while (i != end6) { while (i != end6) {
*i = 7; *i = 7;
++i; ++i;
} }
// vect: [ 3, 3, 7, 7, 7, 8 ] // list: [ 3, 3, 7, 7, 7, 8 ]
//! [21] //! [21]
//! [22] //! [22]
QVector<int> vect; QList<int> list;
vect << 3 << 3 << 6 << 6 << 6 << 8; list << 3 << 3 << 6 << 6 << 6 << 8;
QVector<int>::iterator i = QList<int>::iterator i =
qBinaryFind(vect.begin(), vect.end(), 6); qBinaryFind(list.begin(), list.end(), 6);
// i == vect.begin() + 2 (or 3 or 4) // i == list.begin() + 2 (or 3 or 4)
//! [22] //! [22]

View File

@ -64,23 +64,6 @@ while (i.hasPrevious())
qDebug() << i.previous(); qDebug() << i.previous();
//! [1] //! [1]
//! [4]
QVector<float> vector;
...
QVectorIterator<float> i(vector);
while (i.hasNext())
qDebug() << i.next();
//! [4]
//! [5]
QVectorIterator<float> i(vector);
i.toBack();
while (i.hasPrevious())
qDebug() << i.previous();
//! [5]
//! [6] //! [6]
QSet<QString> set; QSet<QString> set;
... ...
@ -127,35 +110,6 @@ while (i.hasNext()) {
} }
//! [10] //! [10]
//! [14]
QVector<float> vector;
...
QMutableVectorIterator<float> i(vector);
while (i.hasNext())
qDebug() << i.next();
//! [14]
//! [15]
QMutableVectorIterator<float> i(vector);
i.toBack();
while (i.hasPrevious())
qDebug() << i.previous();
//! [15]
//! [16]
QMutableVectorIterator<int> i(vector);
while (i.hasNext()) {
int val = i.next();
if (val < 0) {
i.setValue(-val);
} else if (val == 0) {
i.remove();
}
}
//! [16]
//! [17] //! [17]
QSet<float> set; QSet<float> set;
... ...
@ -182,16 +136,6 @@ while (i.hasNext()) {
} }
//! [19] //! [19]
//! [21]
QMutableVectorIterator<int> i(vector);
while (i.hasNext()) {
int val = i.next();
if (val < -32768 || val > 32767)
i.remove();
}
//! [21]
//! [22] //! [22]
QMutableSetIterator<int> i(set); QMutableSetIterator<int> i(set);
while (i.hasNext()) { while (i.hasNext()) {
@ -210,15 +154,6 @@ while (i.hasNext()) {
} }
//! [23] //! [23]
//! [25]
QMutableVectorIterator<double> i(list);
while (i.hasNext()) {
double val = i.next();
i.setValue(std::sqrt(val));
}
//! [25]
//! [26] //! [26]
QMap<int, QWidget *> map; QMap<int, QWidget *> map;
... ...

View File

@ -95,9 +95,9 @@
//! [8] //! [8]
//! [9] //! [9]
QVector<quint32> vector; QList<quint32> list;
vector.resize(16); list.resize(16);
QRandomGenerator::global()->fillRange(vector.data(), vector.size()); QRandomGenerator::global()->fillRange(list.data(), list.size());
//! [9] //! [9]
//! [10] //! [10]

View File

@ -208,7 +208,7 @@
//! [19] //! [19]
//! [20] //! [20]
void appendList(QCborStreamWriter &writer, const QVector<QString> &values) void appendList(QCborStreamWriter &writer, const QList<QString> &values)
{ {
writer.startArray(); writer.startArray();
for (const QString &s : values) for (const QString &s : values)
@ -228,7 +228,7 @@
//! [21] //! [21]
//! [22] //! [22]
void appendMap(QCborStreamWriter &writer, const QVector<QPair<int, QString>> &values) void appendMap(QCborStreamWriter &writer, const QList<QPair<int, QString>> &values)
{ {
writer.startMap(); writer.startMap();
for (const auto pair : values) { for (const auto pair : values) {

View File

@ -49,162 +49,162 @@
****************************************************************************/ ****************************************************************************/
//! [0] //! [0]
QList<int> integerVector; QList<int> integerList;
QList<QString> stringVector; QList<QString> stringList;
//! [0] //! [0]
//! [1] //! [1]
QList<QString> vector(200); QList<QString> list(200);
//! [1] //! [1]
//! [2] //! [2]
QList<QString> vector(200, "Pass"); QList<QString> list(200, "Pass");
//! [2] //! [2]
//! [3] //! [3]
if (vector[0] == "Liz") if (list[0] == "Liz")
vector[0] = "Elizabeth"; list[0] = "Elizabeth";
//! [3] //! [3]
//! [4] //! [4]
for (int i = 0; i < vector.size(); ++i) { for (int i = 0; i < list.size(); ++i) {
if (vector.at(i) == "Alfonso") if (list.at(i) == "Alfonso")
cout << "Found Alfonso at position " << i << Qt::endl; cout << "Found Alfonso at position " << i << Qt::endl;
} }
//! [4] //! [4]
//! [5] //! [5]
int i = vector.indexOf("Harumi"); int i = list.indexOf("Harumi");
if (i != -1) if (i != -1)
cout << "First occurrence of Harumi is at position " << i << Qt::endl; cout << "First occurrence of Harumi is at position " << i << Qt::endl;
//! [5] //! [5]
//! [6] //! [6]
QList<int> vector(10); QList<int> list(10);
int *data = vector.data(); int *data = list.data();
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
data[i] = 2 * i; data[i] = 2 * i;
//! [6] //! [6]
//! [7] //! [7]
QList<QString> vector; QList<QString> list;
vector.append("one"); list.append("one");
vector.append("two"); list.append("two");
QString three = "three"; QString three = "three";
vector.append(three); list.append(three);
// vector: ["one", "two", "three"] // list: ["one", "two", "three"]
// three: "three" // three: "three"
//! [7] //! [7]
//! [move-append] //! [move-append]
QList<QString> vector; QList<QString> list;
vector.append("one"); list.append("one");
vector.append("two"); list.append("two");
QString three = "three"; QString three = "three";
vector.append(std::move(three)); list.append(std::move(three));
// vector: ["one", "two", "three"] // list: ["one", "two", "three"]
// three: "" // three: ""
//! [move-append] //! [move-append]
//! [emplace] //! [emplace]
QList<QString> vector{"a", "ccc"}; QList<QString> list{"a", "ccc"};
vector.emplace(1, 2, 'b'); list.emplace(1, 2, 'b');
// vector: ["a", "bb", "ccc"] // list: ["a", "bb", "ccc"]
//! [emplace] //! [emplace]
//! [emplace-back] //! [emplace-back]
QList<QString> vector{"one", "two"}; QList<QString> list{"one", "two"};
vector.emplaceBack(3, 'a'); list.emplaceBack(3, 'a');
qDebug() << vector; qDebug() << list;
// vector: ["one", "two", "aaa"] // list: ["one", "two", "aaa"]
//! [emplace-back] //! [emplace-back]
//! [emplace-back-ref] //! [emplace-back-ref]
QList<QString> vector; QList<QString> list;
auto &ref = vector.emplaceBack(); auto &ref = list.emplaceBack();
ref = "one"; ref = "one";
// vector: ["one"] // list: ["one"]
//! [emplace-back-ref] //! [emplace-back-ref]
//! [8] //! [8]
QList<QString> vector; QList<QString> list;
vector.prepend("one"); list.prepend("one");
vector.prepend("two"); list.prepend("two");
vector.prepend("three"); list.prepend("three");
// vector: ["three", "two", "one"] // list: ["three", "two", "one"]
//! [8] //! [8]
//! [9] //! [9]
QList<QString> vector; QList<QString> list;
vector << "alpha" << "beta" << "delta"; list << "alpha" << "beta" << "delta";
vector.insert(2, "gamma"); list.insert(2, "gamma");
// vector: ["alpha", "beta", "gamma", "delta"] // list: ["alpha", "beta", "gamma", "delta"]
//! [9] //! [9]
//! [10] //! [10]
QList<double> vector; QList<double> list;
vector << 2.718 << 1.442 << 0.4342; list << 2.718 << 1.442 << 0.4342;
vector.insert(1, 3, 9.9); list.insert(1, 3, 9.9);
// vector: [2.718, 9.9, 9.9, 9.9, 1.442, 0.4342] // list: [2.718, 9.9, 9.9, 9.9, 1.442, 0.4342]
//! [10] //! [10]
//! [11] //! [11]
QList<QString> vector(3); QList<QString> list(3);
vector.fill("Yes"); list.fill("Yes");
// vector: ["Yes", "Yes", "Yes"] // list: ["Yes", "Yes", "Yes"]
vector.fill("oh", 5); list.fill("oh", 5);
// vector: ["oh", "oh", "oh", "oh", "oh"] // list: ["oh", "oh", "oh", "oh", "oh"]
//! [11] //! [11]
//! [12] //! [12]
QList<QString> vector; QList<QString> list;
vector << "A" << "B" << "C" << "B" << "A"; list << "A" << "B" << "C" << "B" << "A";
vector.indexOf("B"); // returns 1 list.indexOf("B"); // returns 1
vector.indexOf("B", 1); // returns 1 list.indexOf("B", 1); // returns 1
vector.indexOf("B", 2); // returns 3 list.indexOf("B", 2); // returns 3
vector.indexOf("X"); // returns -1 list.indexOf("X"); // returns -1
//! [12] //! [12]
//! [13] //! [13]
QList<QString> vector; QList<QString> list;
vector << "A" << "B" << "C" << "B" << "A"; list << "A" << "B" << "C" << "B" << "A";
vector.lastIndexOf("B"); // returns 3 list.lastIndexOf("B"); // returns 3
vector.lastIndexOf("B", 3); // returns 3 list.lastIndexOf("B", 3); // returns 3
vector.lastIndexOf("B", 2); // returns 1 list.lastIndexOf("B", 2); // returns 1
vector.lastIndexOf("X"); // returns -1 list.lastIndexOf("X"); // returns -1
//! [13] //! [13]
//! [16] //! [16]
std::vector<double> stdvector; std::vector<double> stdvector;
vector.push_back(1.2); stdvector.push_back(1.2);
vector.push_back(0.5); stdvector.push_back(0.5);
vector.push_back(3.14); stdvector.push_back(3.14);
QList<double> vector = QList<double>::fromStdVector(stdvector); QList<double> list = QList<double>::fromStdVector(stdvector);
//! [16] //! [16]
//! [17] //! [17]
QList<double> vector; QList<double> list;
vector << 1.2 << 0.5 << 3.14; list << 1.2 << 0.5 << 3.14;
std::vector<double> stdvector = vector.toStdVector(); std::vector<double> stdlist = list.toStdVector();
//! [17] //! [17]

View File

@ -1,280 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
//! [0]
QList<int> integerList;
QList<QDate> dateList;
//! [0]
//! [1a]
QList<QString> list = { "one", "two", "three" };
//! [1a]
//! [1b]
list << "four" << "five";
//! [1b]
//! [2]
if (list[0] == "Bob")
list[0] = "Robert";
//! [2]
//! [3]
for (int i = 0; i < list.size(); ++i) {
if (list.at(i) == "Jane")
cout << "Found Jane at position " << i << Qt::endl;
}
//! [3]
//! [4]
QList<QWidget *> list;
...
while (!list.isEmpty())
delete list.takeFirst();
//! [4]
//! [5]
int i = list.indexOf("Jane");
if (i != -1)
cout << "First occurrence of Jane is at position " << i << Qt::endl;
//! [5]
//! [6]
QList<QString> list;
list.append("one");
list.append("two");
list.append("three");
// list: ["one", "two", "three"]
//! [6]
//! [7]
QList<QString> list;
list.prepend("one");
list.prepend("two");
list.prepend("three");
// list: ["three", "two", "one"]
//! [7]
//! [8]
QList<QString> list;
list << "alpha" << "beta" << "delta";
list.insert(2, "gamma");
// list: ["alpha", "beta", "gamma", "delta"]
//! [8]
//! [9]
QList<QString> list;
list << "sun" << "cloud" << "sun" << "rain";
list.removeAll("sun");
// list: ["cloud", "rain"]
//! [9]
//! [10]
QList<QString> list;
list << "sun" << "cloud" << "sun" << "rain";
list.removeOne("sun");
// list: ["cloud", "sun", "rain"]
//! [10]
//! [11]
QList<QString> list;
list << "A" << "B" << "C" << "D" << "E" << "F";
list.move(1, 4);
// list: ["A", "C", "D", "E", "B", "F"]
//! [11]
//! [12]
QList<QString> list;
list << "A" << "B" << "C" << "D" << "E" << "F";
list.swapItemsAt(1, 4);
// list: ["A", "E", "C", "D", "B", "F"]
//! [12]
//! [13]
QList<QString> list;
list << "A" << "B" << "C" << "B" << "A";
list.indexOf("B"); // returns 1
list.indexOf("B", 1); // returns 1
list.indexOf("B", 2); // returns 3
list.indexOf("X"); // returns -1
//! [13]
//! [14]
QList<QString> list;
list << "A" << "B" << "C" << "B" << "A";
list.lastIndexOf("B"); // returns 3
list.lastIndexOf("B", 3); // returns 3
list.lastIndexOf("B", 2); // returns 1
list.lastIndexOf("X"); // returns -1
//! [14]
//! [15]
QList<QString> list;
list.append("January");
list.append("February");
...
list.append("December");
QList<QString>::iterator i;
for (i = list.begin(); i != list.end(); ++i)
cout << *i << Qt::endl;
//! [15]
//! [16]
QList<int>::iterator i;
for (i = list.begin(); i != list.end(); ++i)
*i += 2;
//! [16]
//! [17]
QList<QWidget *> list;
...
qDeleteAll(list.begin(), list.end());
//! [17]
//! [18]
if (*it == "Hello")
*it = "Bonjour";
//! [18]
//! [19]
QList<QString> list;
list.append("January");
list.append("February");
...
list.append("December");
QList<QString>::const_iterator i;
for (i = list.constBegin(); i != list.constEnd(); ++i)
cout << *i << Qt::endl;
//! [19]
//! [20]
QList<QWidget *> list;
...
qDeleteAll(list.constBegin(), list.constEnd());
//! [20]
//! [21]
QVector<double> vect;
vect << 20.0 << 30.0 << 40.0 << 50.0;
QList<double> list = QVector<T>::fromVector(vect);
// list: [20.0, 30.0, 40.0, 50.0]
//! [21]
//! [22]
QStringList list;
list << "Sven" << "Kim" << "Ola";
QVector<QString> vect = list.toVector();
// vect: ["Sven", "Kim", "Ola"]
//! [22]
//! [23]
QSet<int> set;
set << 20 << 30 << 40 << ... << 70;
QList<int> list = QList<int>::fromSet(set);
std::sort(list.begin(), list.end());
//! [23]
//! [24]
QStringList list;
list << "Julia" << "Mike" << "Mike" << "Julia" << "Julia";
QSet<QString> set = list.toSet();
set.contains("Julia"); // returns true
set.contains("Mike"); // returns true
set.size(); // returns 2
//! [24]
//! [25]
std::list<double> stdlist;
list.push_back(1.2);
list.push_back(0.5);
list.push_back(3.14);
QList<double> list = QList<double>::fromStdList(stdlist);
//! [25]
//! [26]
QList<double> list;
list << 1.2 << 0.5 << 3.14;
std::list<double> stdlist = list.toStdList();
//! [26]

View File

@ -42,7 +42,7 @@
The Qt library provides a set of general purpose template-based The Qt library provides a set of general purpose template-based
container classes. These classes can be used to store items of a container classes. These classes can be used to store items of a
specified type. For example, if you need a resizable array of specified type. For example, if you need a resizable array of
\l{QString}s, use QVector<QString>. \l{QString}s, use QList<QString>.
These container classes are designed to be lighter, safer, and These container classes are designed to be lighter, safer, and
easier to use than the STL containers. If you are unfamiliar with easier to use than the STL containers. If you are unfamiliar with
@ -74,9 +74,9 @@
\section1 The Container Classes \section1 The Container Classes
Qt provides the following sequential containers: QVector, Qt provides the following sequential containers: QList,
QStack, and QQueue. For most QStack, and QQueue. For most
applications, QVector is the best type to use. It provides very fast applications, QList is the best type to use. It provides very fast
appends. If you really need a linked-list, use std::list. appends. If you really need a linked-list, use std::list.
QStack and QQueue are convenience classes that provide LIFO and QStack and QQueue are convenience classes that provide LIFO and
FIFO semantics. FIFO semantics.
@ -93,30 +93,30 @@
\table \table
\header \li Class \li Summary \header \li Class \li Summary
\row \li \l{QVector}<T> \row \li \l{QList}<T>
\li This is by far the most commonly used container class. It \li This is by far the most commonly used container class. It
stores a list of values of a given type (T) that can be accessed stores a list of values of a given type (T) that can be accessed
by index. Internally, it stores an array of values of a by index. Internally, it stores an array of values of a
given type at adjacent given type at adjacent
positions in memory. Inserting at the front or in the middle of positions in memory. Inserting at the front or in the middle of
a vector can be quite slow, because it can lead to large numbers a list can be quite slow, because it can lead to large numbers
of items having to be moved by one position in memory. of items having to be moved by one position in memory.
\row \li \l{QVarLengthArray}<T, Prealloc> \row \li \l{QVarLengthArray}<T, Prealloc>
\li This provides a low-level variable-length array. It can be used \li This provides a low-level variable-length array. It can be used
instead of QVector in places where speed is particularly important. instead of QList in places where speed is particularly important.
\row \li \l{QStack}<T> \row \li \l{QStack}<T>
\li This is a convenience subclass of QVector that provides \li This is a convenience subclass of QList that provides
"last in, first out" (LIFO) semantics. It adds the following "last in, first out" (LIFO) semantics. It adds the following
functions to those already present in QVector: functions to those already present in QList:
\l{QStack::push()}{push()}, \l{QStack::pop()}{pop()}, \l{QStack::push()}{push()}, \l{QStack::pop()}{pop()},
and \l{QStack::top()}{top()}. and \l{QStack::top()}{top()}.
\row \li \l{QQueue}<T> \row \li \l{QQueue}<T>
\li This is a convenience subclass of QVector that provides \li This is a convenience subclass of QList that provides
"first in, first out" (FIFO) semantics. It adds the following "first in, first out" (FIFO) semantics. It adds the following
functions to those already present in QQVector: functions to those already present in QList:
\l{QQueue::enqueue()}{enqueue()}, \l{QQueue::enqueue()}{enqueue()},
\l{QQueue::dequeue()}{dequeue()}, and \l{QQueue::head()}{head()}. \l{QQueue::dequeue()}{dequeue()}, and \l{QQueue::head()}{head()}.
@ -147,11 +147,11 @@
\endtable \endtable
Containers can be nested. For example, it is perfectly possible Containers can be nested. For example, it is perfectly possible
to use a QMap<QString, QVector<int>>, where the key type is to use a QMap<QString, QList<int>>, where the key type is
QString and the value type QVector<int>. QString and the value type QList<int>.
The containers are defined in individual header files with the The containers are defined in individual header files with the
same name as the container (e.g., \c <QVector>). For same name as the container (e.g., \c <QList>). For
convenience, the containers are forward declared in \c convenience, the containers are forward declared in \c
<QtContainerFwd>. <QtContainerFwd>.
@ -167,10 +167,10 @@
double, pointer types, and Qt data types such as QString, QDate, double, pointer types, and Qt data types such as QString, QDate,
and QTime, but it doesn't cover QObject or any QObject subclass and QTime, but it doesn't cover QObject or any QObject subclass
(QWidget, QDialog, QTimer, etc.). If you attempt to instantiate a (QWidget, QDialog, QTimer, etc.). If you attempt to instantiate a
QVector<QWidget>, the compiler will complain that QWidget's copy QList<QWidget>, the compiler will complain that QWidget's copy
constructor and assignment operators are disabled. If you want to constructor and assignment operators are disabled. If you want to
store these kinds of objects in a container, store them as store these kinds of objects in a container, store them as
pointers, for example as QVector<QWidget *>. pointers, for example as QList<QWidget *>.
Here's an example custom data type that meets the requirement of Here's an example custom data type that meets the requirement of
an assignable data type: an assignable data type:
@ -210,7 +210,7 @@
\target default-constructed value \target default-constructed value
The documentation of certain container class functions refer to The documentation of certain container class functions refer to
\e{default-constructed values}; for example, QVector \e{default-constructed values}; for example, QList
automatically initializes its items with default-constructed automatically initializes its items with default-constructed
values, and QMap::value() returns a default-constructed value if values, and QMap::value() returns a default-constructed value if
the specified key isn't in the map. For most value types, this the specified key isn't in the map. For most value types, this
@ -241,22 +241,22 @@
read-write access. read-write access.
\table \table
\header \li Containers \li Read-only iterator \header \li Containers \li Read-only iterator
\li Read-write iterator \li Read-write iterator
\li QMutableListIterator<T> \li QMutableListIterator<T>
\row \li QVector<T>, QStack<T>, QQueue<T> \li QVectorIterator<T> \row \li QList<T>, QQueue<T>, QStack<T>, \li QListIterator<T>
\li QMutableVectorIterator<T> \li QMutableListIterator<T>
\row \li QSet<T> \li QSetIterator<T> \row \li QSet<T> \li QSetIterator<T>
\li QMutableSetIterator<T> \li QMutableSetIterator<T>
\row \li QMap<Key, T>, QMultiMap<Key, T> \li QMapIterator<Key, T> \row \li QMap<Key, T>, QMultiMap<Key, T> \li QMapIterator<Key, T>
\li QMutableMapIterator<Key, T> \li QMutableMapIterator<Key, T>
\row \li QHash<Key, T>, QMultiHash<Key, T> \li QHashIterator<Key, T> \row \li QHash<Key, T>, QMultiHash<Key, T> \li QHashIterator<Key, T>
\li QMutableHashIterator<Key, T> \li QMutableHashIterator<Key, T>
\endtable \endtable
In this discussion, we will concentrate on QVector and QMap. The In this discussion, we will concentrate on QList and QMap. The
iterator types for QSet have exactly iterator types for QSet have exactly
the same interface as QVector's iterators; similarly, the iterator the same interface as QList's iterators; similarly, the iterator
types for QHash have the same interface as QMap's iterators. types for QHash have the same interface as QMap's iterators.
Unlike STL-style iterators (covered \l{STL-style Unlike STL-style iterators (covered \l{STL-style
@ -271,59 +271,59 @@
\image javaiterators1.png \image javaiterators1.png
Here's a typical loop for iterating through all the elements of a Here's a typical loop for iterating through all the elements of a
QVector<QString> in order and printing them to the console: QList<QString> in order and printing them to the console:
\snippet code/doc_src_containers.cpp 1 \snippet code/doc_src_containers.cpp 1
It works as follows: The QVector to iterate over is passed to the It works as follows: The QList to iterate over is passed to the
QVectorIterator constructor. At that point, the iterator is located QListIterator constructor. At that point, the iterator is located
just in front of the first item in the list (before item "A"). just in front of the first item in the list (before item "A").
Then we call \l{QVectorIterator::hasNext()}{hasNext()} to Then we call \l{QListIterator::hasNext()}{hasNext()} to
check whether there is an item after the iterator. If there is, we check whether there is an item after the iterator. If there is, we
call \l{QVectorIterator::next()}{next()} to jump over that call \l{QListIterator::next()}{next()} to jump over that
item. The next() function returns the item that it jumps over. For item. The next() function returns the item that it jumps over. For
a QVector<QString>, that item is of type QString. a QList<QString>, that item is of type QString.
Here's how to iterate backward in a QVector: Here's how to iterate backward in a QList:
\snippet code/doc_src_containers.cpp 2 \snippet code/doc_src_containers.cpp 2
The code is symmetric with iterating forward, except that we The code is symmetric with iterating forward, except that we
start by calling \l{QVectorIterator::toBack()}{toBack()} start by calling \l{QListIterator::toBack()}{toBack()}
to move the iterator after the last item in the list. to move the iterator after the last item in the list.
The diagram below illustrates the effect of calling The diagram below illustrates the effect of calling
\l{QVectorIterator::next()}{next()} and \l{QListIterator::next()}{next()} and
\l{QVectorIterator::previous()}{previous()} on an iterator: \l{QListIterator::previous()}{previous()} on an iterator:
\image javaiterators2.png \image javaiterators2.png
The following table summarizes the QVectorIterator API: The following table summarizes the QListIterator API:
\table \table
\header \li Function \li Behavior \header \li Function \li Behavior
\row \li \l{QVectorIterator::toFront()}{toFront()} \row \li \l{QListIterator::toFront()}{toFront()}
\li Moves the iterator to the front of the list (before the first item) \li Moves the iterator to the front of the list (before the first item)
\row \li \l{QVectorIterator::toBack()}{toBack()} \row \li \l{QListIterator::toBack()}{toBack()}
\li Moves the iterator to the back of the list (after the last item) \li Moves the iterator to the back of the list (after the last item)
\row \li \l{QVectorIterator::hasNext()}{hasNext()} \row \li \l{QListIterator::hasNext()}{hasNext()}
\li Returns \c true if the iterator isn't at the back of the list \li Returns \c true if the iterator isn't at the back of the list
\row \li \l{QVectorIterator::next()}{next()} \row \li \l{QListIterator::next()}{next()}
\li Returns the next item and advances the iterator by one position \li Returns the next item and advances the iterator by one position
\row \li \l{QVectorIterator::peekNext()}{peekNext()} \row \li \l{QListIterator::peekNext()}{peekNext()}
\li Returns the next item without moving the iterator \li Returns the next item without moving the iterator
\row \li \l{QVectorIterator::hasPrevious()}{hasPrevious()} \row \li \l{QListIterator::hasPrevious()}{hasPrevious()}
\li Returns \c true if the iterator isn't at the front of the list \li Returns \c true if the iterator isn't at the front of the list
\row \li \l{QVectorIterator::previous()}{previous()} \row \li \l{QListIterator::previous()}{previous()}
\li Returns the previous item and moves the iterator back by one position \li Returns the previous item and moves the iterator back by one position
\row \li \l{QVectorIterator::peekPrevious()}{peekPrevious()} \row \li \l{QListIterator::peekPrevious()}{peekPrevious()}
\li Returns the previous item without moving the iterator \li Returns the previous item without moving the iterator
\endtable \endtable
QVectorIterator provides no functions to insert or remove items QListIterator provides no functions to insert or remove items
from the list as we iterate. To accomplish this, you must use from the list as we iterate. To accomplish this, you must use
QMutableListIterator. Here's an example where we remove all QMutableListIterator. Here's an example where we remove all
odd numbers from a QVector<int> using QMutableListIterator: odd numbers from a QList<int> using QMutableListIterator:
\snippet code/doc_src_containers.cpp 3 \snippet code/doc_src_containers.cpp 3
@ -357,11 +357,11 @@
\snippet code/doc_src_containers.cpp 6 \snippet code/doc_src_containers.cpp 6
As mentioned above QSet's iterator As mentioned above QSet's iterator
classes have exactly the same API as QVector's. We will now turn to classes have exactly the same API as QList's. We will now turn to
QMapIterator, which is somewhat different because it iterates on QMapIterator, which is somewhat different because it iterates on
(key, value) pairs. (key, value) pairs.
Like QVectorIterator, QMapIterator provides Like QListIterator, QMapIterator provides
\l{QMapIterator::toFront()}{toFront()}, \l{QMapIterator::toFront()}{toFront()},
\l{QMapIterator::toBack()}{toBack()}, \l{QMapIterator::toBack()}{toBack()},
\l{QMapIterator::hasNext()}{hasNext()}, \l{QMapIterator::hasNext()}{hasNext()},
@ -407,48 +407,48 @@
possible because they are faster than read-write iterators. possible because they are faster than read-write iterators.
\table \table
\header \li Containers \li Read-only iterator \header \li Containers \li Read-only iterator
\li Read-write iterator \li Read-write iterator
\row \li QVector<T>, QStack<T>, QQueue<T> \li QVector<T>::const_iterator \row \li QList<T>, QStack<T>, QQueue<T> \li QList<T>::const_iterator
\li QVector<T>::iterator \li QList<T>::iterator
\row \li QSet<T> \li QSet<T>::const_iterator \row \li QSet<T> \li QSet<T>::const_iterator
\li QSet<T>::iterator \li QSet<T>::iterator
\row \li QMap<Key, T>, QMultiMap<Key, T> \li QMap<Key, T>::const_iterator \row \li QMap<Key, T>, QMultiMap<Key, T> \li QMap<Key, T>::const_iterator
\li QMap<Key, T>::iterator \li QMap<Key, T>::iterator
\row \li QHash<Key, T>, QMultiHash<Key, T> \li QHash<Key, T>::const_iterator \row \li QHash<Key, T>, QMultiHash<Key, T> \li QHash<Key, T>::const_iterator
\li QHash<Key, T>::iterator \li QHash<Key, T>::iterator
\endtable \endtable
The API of the STL iterators is modelled on pointers in an array. The API of the STL iterators is modelled on pointers in an array.
For example, the \c ++ operator advances the iterator to the next For example, the \c ++ operator advances the iterator to the next
item, and the \c * operator returns the item that the iterator item, and the \c * operator returns the item that the iterator
points to. In fact, for QVector and QStack, which store their points to. In fact, for QList and QStack, which store their
items at adjacent memory positions, the items at adjacent memory positions, the
\l{QVector::iterator}{iterator} type is just a typedef for \c{T *}, \l{QList::iterator}{iterator} type is just a typedef for \c{T *},
and the \l{QVector::iterator}{const_iterator} type is and the \l{QList::iterator}{const_iterator} type is
just a typedef for \c{const T *}. just a typedef for \c{const T *}.
In this discussion, we will concentrate on QVector and QMap. The In this discussion, we will concentrate on QList and QMap. The
iterator types for QSet have exactly iterator types for QSet have exactly
the same interface as QVector's iterators; similarly, the iterator the same interface as QList's iterators; similarly, the iterator
types for QHash have the same interface as QMap's iterators. types for QHash have the same interface as QMap's iterators.
Here's a typical loop for iterating through all the elements of a Here's a typical loop for iterating through all the elements of a
QVector<QString> in order and converting them to lowercase: QList<QString> in order and converting them to lowercase:
\snippet code/doc_src_containers.cpp 10 \snippet code/doc_src_containers.cpp 10
Unlike \l{Java-style iterators}, STL-style iterators point Unlike \l{Java-style iterators}, STL-style iterators point
directly at items. The \l{QVector::begin()}{begin()} function of a container returns an directly at items. The \l{QList::begin()}{begin()} function of a container returns an
iterator that points to the first item in the container. The iterator that points to the first item in the container. The
\l{QVector::end()}{end()} function of a container returns an iterator to the \l{QList::end()}{end()} function of a container returns an iterator to the
imaginary item one position past the last item in the container. imaginary item one position past the last item in the container.
\l {QVector::end()}{end()} marks an invalid position; it must never be dereferenced. \l {QList::end()}{end()} marks an invalid position; it must never be dereferenced.
It is typically used in a loop's break condition. If the list is It is typically used in a loop's break condition. If the list is
empty, \l{QVector::begin}{begin()} equals \l{QVector::end()}{end()}, so we never execute the loop. empty, \l{QList::begin}{begin()} equals \l{QList::end()}{end()}, so we never execute the loop.
The diagram below shows the valid iterator positions as red The diagram below shows the valid iterator positions as red
arrows for a vector containing four items: arrows for a list containing four items:
\image stliterators1.png \image stliterators1.png
@ -462,8 +462,8 @@
compilers also allow us to write \c{i->toLower()}, but some compilers also allow us to write \c{i->toLower()}, but some
don't. don't.
For read-only access, you can use const_iterator, \l{QVector::constBegin}{constBegin()}, For read-only access, you can use const_iterator, \l{QList::constBegin}{constBegin()},
and \l{QVector::constEnd()}{constEnd()}. For example: and \l{QList::constEnd()}{constEnd()}. For example:
\snippet code/doc_src_containers.cpp 12 \snippet code/doc_src_containers.cpp 12
@ -501,7 +501,7 @@
Thanks to \l{implicit sharing}, it is very inexpensive for a Thanks to \l{implicit sharing}, it is very inexpensive for a
function to return a container per value. The Qt API contains function to return a container per value. The Qt API contains
dozens of functions that return a QVector or QStringList per value dozens of functions that return a QList or QStringList per value
(e.g., QSplitter::sizes()). If you want to iterate over these (e.g., QSplitter::sizes()). If you want to iterate over these
using an STL iterator, you should always take a copy of the using an STL iterator, you should always take a copy of the
container and iterate over the copy. For example: container and iterate over the copy. For example:
@ -521,7 +521,7 @@
\snippet code/doc_src_containers.cpp 24 \snippet code/doc_src_containers.cpp 24
The above example only shows a problem with QVector, but The above example only shows a problem with QList, but
the problem exists for all the implicitly shared Qt containers. the problem exists for all the implicitly shared Qt containers.
\target foreach \target foreach
@ -534,7 +534,7 @@
Its syntax is: \c foreach (\e variable, \e container) \e Its syntax is: \c foreach (\e variable, \e container) \e
statement. For example, here's how to use \c foreach to iterate statement. For example, here's how to use \c foreach to iterate
over a QVector<QString>: over a QList<QString>:
\snippet code/doc_src_containers.cpp 15 \snippet code/doc_src_containers.cpp 15
@ -620,8 +620,8 @@
example, inserting an item in the middle of a std::list is an example, inserting an item in the middle of a std::list is an
extremely fast operation, irrespective of the number of items extremely fast operation, irrespective of the number of items
stored in the list. On the other hand, inserting an item stored in the list. On the other hand, inserting an item
in the middle of a QVector is potentially very expensive if the in the middle of a QList is potentially very expensive if the
QVector contains many items, since half of the items must be QList contains many items, since half of the items must be
moved one position in memory. moved one position in memory.
To describe algorithmic complexity, we use the following To describe algorithmic complexity, we use the following
@ -637,7 +637,7 @@
\li \b{Constant time:} O(1). A function is said to run in constant \li \b{Constant time:} O(1). A function is said to run in constant
time if it requires the same amount of time no matter how many time if it requires the same amount of time no matter how many
items are present in the container. One example is items are present in the container. One example is
QVector::push_back(). QList::push_back().
\li \b{Logarithmic time:} O(log \e n). A function that runs in \li \b{Logarithmic time:} O(log \e n). A function that runs in
logarithmic time is a function whose running time is logarithmic time is a function whose running time is
@ -647,7 +647,7 @@
\li \b{Linear time:} O(\e n). A function that runs in linear time \li \b{Linear time:} O(\e n). A function that runs in linear time
will execute in a time directly proportional to the number of will execute in a time directly proportional to the number of
items stored in the container. One example is items stored in the container. One example is
QVector::insert(). QList::insert().
\li \b{Linear-logarithmic time:} O(\e{n} log \e n). A function \li \b{Linear-logarithmic time:} O(\e{n} log \e n). A function
that runs in linear-logarithmic time is asymptotically slower that runs in linear-logarithmic time is asymptotically slower
@ -660,11 +660,11 @@
\endlist \endlist
The following table summarizes the algorithmic complexity of the sequential The following table summarizes the algorithmic complexity of the sequential
container QVector<T>: container QList<T>:
\table \table
\header \li \li Index lookup \li Insertion \li Prepending \li Appending \header \li \li Index lookup \li Insertion \li Prepending \li Appending
\row \li QVector<T> \li O(1) \li O(n) \li O(n) \li Amort. O(1) \row \li QList<T> \li O(1) \li O(n) \li O(n) \li Amort. O(1)
\endtable \endtable
In the table, "Amort." stands for "amortized behavior". For In the table, "Amort." stands for "amortized behavior". For
@ -685,15 +685,15 @@
\row \li QSet<Key> \li Amort. O(1) \li O(\e n) \li Amort. O(1) \li O(\e n) \row \li QSet<Key> \li Amort. O(1) \li O(\e n) \li Amort. O(1) \li O(\e n)
\endtable \endtable
With QVector, QHash, and QSet, the performance of appending items With QList, QHash, and QSet, the performance of appending items
is amortized O(log \e n). It can be brought down to O(1) by is amortized O(log \e n). It can be brought down to O(1) by
calling QVector::reserve(), QHash::reserve(), or QSet::reserve() calling QList::reserve(), QHash::reserve(), or QSet::reserve()
with the expected number of items before you insert the items. with the expected number of items before you insert the items.
The next section discusses this topic in more depth. The next section discusses this topic in more depth.
\section1 Growth Strategies \section1 Growth Strategies
QVector<T>, QString, and QByteArray store their items QList<T>, QString, and QByteArray store their items
contiguously in memory; QHash<Key, T> keeps a contiguously in memory; QHash<Key, T> keeps a
hash table whose size is proportional to the number hash table whose size is proportional to the number
of items in the hash. To avoid reallocating the data every single of items in the hash. To avoid reallocating the data every single
@ -732,12 +732,12 @@
QByteArray uses more or less the same algorithm as QByteArray uses more or less the same algorithm as
QString. QString.
QVector<T> also uses that algorithm for data types that can be QList<T> also uses that algorithm for data types that can be
moved around in memory using \c memcpy() (including the basic C++ moved around in memory using \c memcpy() (including the basic C++
types, the pointer types, and Qt's \l{shared classes}) but uses a types, the pointer types, and Qt's \l{shared classes}) but uses a
different algorithm for data types that can only be moved by different algorithm for data types that can only be moved by
calling the copy constructor and a destructor. Since the cost of calling the copy constructor and a destructor. Since the cost of
reallocating is higher in that case, QVector<T> reduces the reallocating is higher in that case, QList<T> reduces the
number of reallocations by always doubling the memory when number of reallocations by always doubling the memory when
running out of space. running out of space.
@ -748,7 +748,7 @@
QSet<T> and QCache<Key, T> as well. QSet<T> and QCache<Key, T> as well.
For most applications, the default growing algorithm provided by For most applications, the default growing algorithm provided by
Qt does the trick. If you need more control, QVector<T>, Qt does the trick. If you need more control, QList<T>,
QHash<Key, T>, QSet<T>, QString, and QByteArray provide a trio of QHash<Key, T>, QSet<T>, QString, and QByteArray provide a trio of
functions that allow you to check and specify how much memory to functions that allow you to check and specify how much memory to
use to store the items: use to store the items:

View File

@ -66,6 +66,7 @@
\li QIcon \li QIcon
\li QImage \li QImage
\li QKeySequence \li QKeySequence
\li QList<T>
\li QMap<Key, T> \li QMap<Key, T>
\li QMargins \li QMargins
\li QMatrix4x4 \li QMatrix4x4
@ -88,7 +89,6 @@
\li QVector2D \li QVector2D
\li QVector3D \li QVector3D
\li QVector4D \li QVector4D
\li QVector<T>
\endlist \endlist
\sa {JSON Support in Qt} \sa {JSON Support in Qt}

View File

@ -139,7 +139,7 @@
is called for \c p2, because painting a pixmap will modify it. is called for \c p2, because painting a pixmap will modify it.
\warning Be careful with copying an implicitly shared container \warning Be careful with copying an implicitly shared container
(QMap, QVector, etc.) while you use (QMap, QList, etc.) while you use
\l{STL-style iterators}{STL-style iterator}. See \l{Implicit sharing iterator problem}. \l{STL-style iterators}{STL-style iterator}. See \l{Implicit sharing iterator problem}.
\target implicitly shared classes \target implicitly shared classes

View File

@ -811,7 +811,7 @@ inline QRandomGenerator::SystemGenerator &QRandomGenerator::SystemGenerator::sel
efficient way to obtain more than one quantity at a time, as it reduces the efficient way to obtain more than one quantity at a time, as it reduces the
number of calls into the Random Number Generator source. number of calls into the Random Number Generator source.
For example, to fill a vector of 16 entries with random values, one may For example, to fill a list of 16 entries with random values, one may
write: write:
\snippet code/src_corelib_global_qrandom.cpp 9 \snippet code/src_corelib_global_qrandom.cpp 9

View File

@ -729,7 +729,7 @@ void QCborStreamWriter::appendTextString(const char *utf8, qsizetype len)
length is implied by the elements contained in it. Note, however, that use length is implied by the elements contained in it. Note, however, that use
of indeterminate-length arrays is not compliant with canonical CBOR encoding. of indeterminate-length arrays is not compliant with canonical CBOR encoding.
The following example appends elements from the vector of strings The following example appends elements from the list of strings
passed as input: passed as input:
\snippet code/src_corelib_serialization_qcborstream.cpp 20 \snippet code/src_corelib_serialization_qcborstream.cpp 20
@ -802,7 +802,7 @@ bool QCborStreamWriter::endArray()
indeterminate-length maps is not compliant with canonical CBOR encoding indeterminate-length maps is not compliant with canonical CBOR encoding
(canonical encoding also requires keys to be unique and in sorted order). (canonical encoding also requires keys to be unique and in sorted order).
The following example appends elements from the vector of int and The following example appends elements from the list of int and
string pairs passed as input: string pairs passed as input:
\snippet code/src_corelib_serialization_qcborstream.cpp 22 \snippet code/src_corelib_serialization_qcborstream.cpp 22

View File

@ -172,9 +172,9 @@
making it possible to access, modify, and remove items without making it possible to access, modify, and remove items without
using iterators. using iterators.
QListIterator\<T\> allows you to iterate over a QList\<T\> (or a QListIterator\<T\> allows you to iterate over a QList\<T\>,
QQueue\<T\>). If you want to modify the list as you iterate over a QQueue\<T\> or a QStack\<T\>. If you want to modify the list
it, use QMutableListIterator\<T\> instead. as you iterate over it, use QMutableListIterator\<T\> instead.
The QListIterator constructor takes a QList as argument. After The QListIterator constructor takes a QList as argument. After
construction, the iterator is located at the very beginning of construction, the iterator is located at the very beginning of
@ -212,53 +212,9 @@
/*! /*!
\class QVectorIterator \class QVectorIterator
\inmodule QtCore \inmodule QtCore
\brief The QVectorIterator class provides a Java-style const iterator for QVector and QStack. \brief QVectorIterator is an alias for QListIterator.
QVector has both \l{Java-style iterators} and \l{STL-style Please see the QListIterator documentation for details.
iterators}. The Java-style iterators are more high-level and
easier to use than the STL-style iterators; on the other hand,
they are slightly less efficient.
An alternative to using iterators is to use index positions. Most
QVector member functions take an index as their first parameter,
making it possible to access, insert, and remove items without
using iterators.
QVectorIterator\<T\> allows you to iterate over a QVector\<T\>
(or a QStack\<T\>). If you want to modify the vector as you
iterate over it, use QMutableVectorIterator\<T\> instead.
The QVectorIterator constructor takes a QVector as argument.
After construction, the iterator is located at the very beginning
of the vector (before the first item). Here's how to iterate over
all the elements sequentially:
\snippet code/doc_src_qiterator.cpp 4
The next() function returns the next item in the vector and
advances the iterator. Unlike STL-style iterators, Java-style
iterators point \e between items rather than directly \e at
items. The first call to next() advances the iterator to the
position between the first and second item, and returns the first
item; the second call to next() advances the iterator to the
position between the second and third item, returning the second
item; and so on.
\image javaiterators1.png
Here's how to iterate over the elements in reverse order:
\snippet code/doc_src_qiterator.cpp 5
If you want to find all occurrences of a particular value, use
findNext() or findPrevious() in a loop.
Multiple iterators can be used on the same vector. If the vector
is modified while a QVectorIterator is active, the QVectorIterator
will continue iterating over the original vector, ignoring the
modified copy.
\sa QMutableVectorIterator, QVector::const_iterator
*/ */
/*! /*!
@ -312,7 +268,7 @@
\class QMutableListIterator \class QMutableListIterator
\inmodule QtCore \inmodule QtCore
\brief The QMutableListIterator class provides a Java-style non-const iterator for QList and QQueue. \brief The QMutableListIterator class provides a Java-style non-const iterator for QList, QQueue and QStack.
QList has both \l{Java-style iterators} and \l{STL-style QList has both \l{Java-style iterators} and \l{STL-style
iterators}. The Java-style iterators are more high-level and iterators}. The Java-style iterators are more high-level and
@ -377,67 +333,9 @@
/*! /*!
\class QMutableVectorIterator \class QMutableVectorIterator
\inmodule QtCore \inmodule QtCore
\brief QMutableVectorIterator is an alias for QMutableListIterator.
\brief The QMutableVectorIterator class provides a Java-style non-const iterator for QVector and QStack. Please see the QMutableListIterator documentation for details.
QVector has both \l{Java-style iterators} and \l{STL-style
iterators}. The Java-style iterators are more high-level and
easier to use than the STL-style iterators; on the other hand,
they are slightly less efficient.
An alternative to using iterators is to use index positions. Most
QVector member functions take an index as their first parameter,
making it possible to access, insert, and remove items without
using iterators.
QMutableVectorIterator\<T\> allows you to iterate over a
QVector\<T\> and modify the vector. If you don't want to modify
the vector (or have a const QVector), use the slightly faster
QVectorIterator\<T\> instead.
The QMutableVectorIterator constructor takes a QVector as
argument. After construction, the iterator is located at the very
beginning of the list (before the first item). Here's how to
iterate over all the elements sequentially:
\snippet code/doc_src_qiterator.cpp 14
The next() function returns the next item in the vector and
advances the iterator. Unlike STL-style iterators, Java-style
iterators point \e between items rather than directly \e at
items. The first call to next() advances the iterator to the
position between the first and second item, and returns the first
item; the second call to next() advances the iterator to the
position between the second and third item, returning the second
item; and so on.
\image javaiterators1.png
Here's how to iterate over the elements in reverse order:
\snippet code/doc_src_qiterator.cpp 15
If you want to find all occurrences of a particular value, use
findNext() or findPrevious() in a loop.
If you want to remove items as you iterate over the vector, use
remove(). If you want to modify the value of an item, use
setValue(). If you want to insert a new item in the vector, use
insert().
Example:
\snippet code/doc_src_qiterator.cpp 16
The example traverses a vector, replacing negative numbers with
their absolute values, and eliminating zeroes.
Only one mutable iterator can be active on a given vector at any
time. Furthermore, no changes should be done directly to the
vector while the iterator is active (as opposed to through the
iterator), since this could invalidate the iterator and lead to
undefined behavior.
\sa QVectorIterator, QVector::iterator
*/ */
/*! /*!
@ -501,16 +399,6 @@
\sa operator=() \sa operator=()
*/ */
/*!
\fn template <class T> QVectorIterator<T>::QVectorIterator(const QVector<T> &vector)
\fn template <class T> QMutableVectorIterator<T>::QMutableVectorIterator(QVector<T> &vector)
Constructs an iterator for traversing \a vector. The iterator is
set to be at the front of the vector (before the first item).
\sa operator=()
*/
/*! /*!
\fn template <class T> QSetIterator<T>::QSetIterator(const QSet<T> &set) \fn template <class T> QSetIterator<T>::QSetIterator(const QSet<T> &set)
\fn template <class T> QMutableSetIterator<T>::QMutableSetIterator(QSet<T> &set) \fn template <class T> QMutableSetIterator<T>::QMutableSetIterator(QSet<T> &set)
@ -530,15 +418,6 @@
\sa toFront(), toBack() \sa toFront(), toBack()
*/ */
/*! \fn template <class T> QVectorIterator &QVectorIterator<T>::operator=(const QVector<T> &vector)
\fn template <class T> QMutableVectorIterator &QMutableVectorIterator<T>::operator=(QVector<T> &vector)
Makes the iterator operate on \a vector. The iterator is set to be
at the front of the vector (before the first item).
\sa toFront(), toBack()
*/
/*! \fn template <class T> QSetIterator &QSetIterator<T>::operator=(const QSet<T> &set) /*! \fn template <class T> QSetIterator &QSetIterator<T>::operator=(const QSet<T> &set)
\fn template <class T> QMutableSetIterator &QMutableSetIterator<T>::operator=(QSet<T> &set) \fn template <class T> QMutableSetIterator &QMutableSetIterator<T>::operator=(QSet<T> &set)
@ -549,10 +428,8 @@
*/ */
/*! \fn template <class T> void QListIterator<T>::toFront() /*! \fn template <class T> void QListIterator<T>::toFront()
\fn template <class T> void QVectorIterator<T>::toFront()
\fn template <class T> void QSetIterator<T>::toFront() \fn template <class T> void QSetIterator<T>::toFront()
\fn template <class T> void QMutableListIterator<T>::toFront() \fn template <class T> void QMutableListIterator<T>::toFront()
\fn template <class T> void QMutableVectorIterator<T>::toFront()
\fn template <class T> void QMutableSetIterator<T>::toFront() \fn template <class T> void QMutableSetIterator<T>::toFront()
Moves the iterator to the front of the container (before the Moves the iterator to the front of the container (before the
@ -562,10 +439,8 @@
*/ */
/*! \fn template <class T> void QListIterator<T>::toBack() /*! \fn template <class T> void QListIterator<T>::toBack()
\fn template <class T> void QVectorIterator<T>::toBack()
\fn template <class T> void QSetIterator<T>::toBack() \fn template <class T> void QSetIterator<T>::toBack()
\fn template <class T> void QMutableListIterator<T>::toBack() \fn template <class T> void QMutableListIterator<T>::toBack()
\fn template <class T> void QMutableVectorIterator<T>::toBack()
\fn template <class T> void QMutableSetIterator<T>::toBack() \fn template <class T> void QMutableSetIterator<T>::toBack()
Moves the iterator to the back of the container (after the last Moves the iterator to the back of the container (after the last
@ -575,10 +450,8 @@
*/ */
/*! \fn template <class T> bool QListIterator<T>::hasNext() const /*! \fn template <class T> bool QListIterator<T>::hasNext() const
\fn template <class T> bool QVectorIterator<T>::hasNext() const
\fn template <class T> bool QSetIterator<T>::hasNext() const \fn template <class T> bool QSetIterator<T>::hasNext() const
\fn template <class T> bool QMutableListIterator<T>::hasNext() const \fn template <class T> bool QMutableListIterator<T>::hasNext() const
\fn template <class T> bool QMutableVectorIterator<T>::hasNext() const
\fn template <class T> bool QMutableSetIterator<T>::hasNext() const \fn template <class T> bool QMutableSetIterator<T>::hasNext() const
Returns \c true if there is at least one item ahead of the iterator, Returns \c true if there is at least one item ahead of the iterator,
@ -589,7 +462,6 @@
*/ */
/*! \fn template <class T> const T &QListIterator<T>::next() /*! \fn template <class T> const T &QListIterator<T>::next()
\fn template <class T> const T &QVectorIterator<T>::next()
\fn template <class T> const T &QSetIterator<T>::next() \fn template <class T> const T &QSetIterator<T>::next()
\fn template <class T> const T &QMutableSetIterator<T>::next() \fn template <class T> const T &QMutableSetIterator<T>::next()
@ -602,7 +474,6 @@
*/ */
/*! \fn template <class T> T &QMutableListIterator<T>::next() /*! \fn template <class T> T &QMutableListIterator<T>::next()
\fn template <class T> T &QMutableVectorIterator<T>::next()
Returns a reference to the next item, and advances the iterator Returns a reference to the next item, and advances the iterator
by one position. by one position.
@ -614,7 +485,6 @@
*/ */
/*! \fn template <class T> const T &QListIterator<T>::peekNext() const /*! \fn template <class T> const T &QListIterator<T>::peekNext() const
\fn template <class T> const T &QVectorIterator<T>::peekNext() const
\fn template <class T> const T &QSetIterator<T>::peekNext() const \fn template <class T> const T &QSetIterator<T>::peekNext() const
\fn template <class T> const T &QMutableSetIterator<T>::peekNext() const \fn template <class T> const T &QMutableSetIterator<T>::peekNext() const
@ -627,7 +497,6 @@
*/ */
/*! \fn template <class T> T &QMutableListIterator<T>::peekNext() const /*! \fn template <class T> T &QMutableListIterator<T>::peekNext() const
\fn template <class T> T &QMutableVectorIterator<T>::peekNext() const
Returns a reference to the next item, without moving the iterator. Returns a reference to the next item, without moving the iterator.
@ -649,10 +518,8 @@
*/ */
/*! \fn template <class T> bool QListIterator<T>::hasPrevious() const /*! \fn template <class T> bool QListIterator<T>::hasPrevious() const
\fn template <class T> bool QVectorIterator<T>::hasPrevious() const
\fn template <class T> bool QSetIterator<T>::hasPrevious() const \fn template <class T> bool QSetIterator<T>::hasPrevious() const
\fn template <class T> bool QMutableListIterator<T>::hasPrevious() const \fn template <class T> bool QMutableListIterator<T>::hasPrevious() const
\fn template <class T> bool QMutableVectorIterator<T>::hasPrevious() const
Returns \c true if there is at least one item behind the iterator, Returns \c true if there is at least one item behind the iterator,
i.e. the iterator is \e not at the front of the container; i.e. the iterator is \e not at the front of the container;
@ -675,7 +542,6 @@
*/ */
/*! \fn template <class T> const T &QListIterator<T>::previous() /*! \fn template <class T> const T &QListIterator<T>::previous()
\fn template <class T> const T &QVectorIterator<T>::previous()
\fn template <class T> const T &QSetIterator<T>::previous() \fn template <class T> const T &QSetIterator<T>::previous()
Returns the previous item and moves the iterator back by one Returns the previous item and moves the iterator back by one
@ -688,7 +554,6 @@
*/ */
/*! \fn template <class T> T &QMutableListIterator<T>::previous() /*! \fn template <class T> T &QMutableListIterator<T>::previous()
\fn template <class T> T &QMutableVectorIterator<T>::previous()
Returns a reference to the previous item and moves the iterator Returns a reference to the previous item and moves the iterator
back by one position. back by one position.
@ -712,7 +577,6 @@
*/ */
/*! \fn template <class T> const T &QListIterator<T>::peekPrevious() const /*! \fn template <class T> const T &QListIterator<T>::peekPrevious() const
\fn template <class T> const T &QVectorIterator<T>::peekPrevious() const
\fn template <class T> const T &QSetIterator<T>::peekPrevious() const \fn template <class T> const T &QSetIterator<T>::peekPrevious() const
Returns the previous item without moving the iterator. Returns the previous item without moving the iterator.
@ -724,7 +588,6 @@
*/ */
/*! \fn template <class T> T &QMutableListIterator<T>::peekPrevious() const /*! \fn template <class T> T &QMutableListIterator<T>::peekPrevious() const
\fn template <class T> T &QMutableVectorIterator<T>::peekPrevious() const
Returns a reference to the previous item, without moving the iterator. Returns a reference to the previous item, without moving the iterator.
@ -749,10 +612,8 @@
*/ */
/*! \fn template <class T> bool QListIterator<T>::findNext(const T &value) /*! \fn template <class T> bool QListIterator<T>::findNext(const T &value)
\fn template <class T> bool QVectorIterator<T>::findNext(const T &value)
\fn template <class T> bool QSetIterator<T>::findNext(const T &value) \fn template <class T> bool QSetIterator<T>::findNext(const T &value)
\fn template <class T> bool QMutableListIterator<T>::findNext(const T &value) \fn template <class T> bool QMutableListIterator<T>::findNext(const T &value)
\fn template <class T> bool QMutableVectorIterator<T>::findNext(const T &value)
Searches for \a value starting from the current iterator position Searches for \a value starting from the current iterator position
forward. Returns \c true if \a value is found; otherwise returns \c false. forward. Returns \c true if \a value is found; otherwise returns \c false.
@ -765,10 +626,8 @@
*/ */
/*! \fn template <class T> bool QListIterator<T>::findPrevious(const T &value) /*! \fn template <class T> bool QListIterator<T>::findPrevious(const T &value)
\fn template <class T> bool QVectorIterator<T>::findPrevious(const T &value)
\fn template <class T> bool QSetIterator<T>::findPrevious(const T &value) \fn template <class T> bool QSetIterator<T>::findPrevious(const T &value)
\fn template <class T> bool QMutableListIterator<T>::findPrevious(const T &value) \fn template <class T> bool QMutableListIterator<T>::findPrevious(const T &value)
\fn template <class T> bool QMutableVectorIterator<T>::findPrevious(const T &value)
\fn template <class T> bool QMutableSetIterator<T>::findPrevious(const T &value) \fn template <class T> bool QMutableSetIterator<T>::findPrevious(const T &value)
Searches for \a value starting from the current iterator position Searches for \a value starting from the current iterator position
@ -793,17 +652,6 @@
\sa insert(), setValue() \sa insert(), setValue()
*/ */
/*! \fn template <class T> void QMutableVectorIterator<T>::remove()
Removes the last item that was jumped over using one of the
traversal functions (next(), previous(), findNext(), findPrevious()).
Example:
\snippet code/doc_src_qiterator.cpp 21
\sa insert(), setValue()
*/
/*! \fn template <class T> void QMutableSetIterator<T>::remove() /*! \fn template <class T> void QMutableSetIterator<T>::remove()
Removes the last item that was jumped over using one of the Removes the last item that was jumped over using one of the
@ -829,22 +677,7 @@
\sa value(), remove(), insert() \sa value(), remove(), insert()
*/ */
/*! \fn template <class T> void QMutableVectorIterator<T>::setValue(const T &value) const
Replaces the value of the last item that was jumped over using
one of the traversal functions with \a value.
The traversal functions are next(), previous(), findNext(), and
findPrevious().
Example:
\snippet code/doc_src_qiterator.cpp 25
\sa value(), remove(), insert()
*/
/*! \fn template <class T> const T &QMutableListIterator<T>::value() const /*! \fn template <class T> const T &QMutableListIterator<T>::value() const
\fn template <class T> const T &QMutableVectorIterator<T>::value() const
\fn template <class T> const T &QMutableSetIterator<T>::value() const \fn template <class T> const T &QMutableSetIterator<T>::value() const
Returns the value of the last item that was jumped over using one Returns the value of the last item that was jumped over using one
@ -858,7 +691,6 @@
/*! /*!
\fn template <class T> T &QMutableListIterator<T>::value() \fn template <class T> T &QMutableListIterator<T>::value()
\fn template <class T> T &QMutableVectorIterator<T>::value()
\overload \overload
Returns a non-const reference to the value of the last item that Returns a non-const reference to the value of the last item that
@ -866,7 +698,6 @@
*/ */
/*! \fn template <class T> void QMutableListIterator<T>::insert(const T &value) /*! \fn template <class T> void QMutableListIterator<T>::insert(const T &value)
\fn template <class T> void QMutableVectorIterator<T>::insert(const T &value)
Inserts \a value at the current iterator position. After the Inserts \a value at the current iterator position. After the
call, the iterator is located just after the inserted item. call, the iterator is located just after the inserted item.

View File

@ -74,7 +74,7 @@
\snippet code/src_corelib_tools_qlist.cpp 0 \snippet code/src_corelib_tools_qlist.cpp 0
QList stores its items in a vector (array). Typically, vectors QList stores its items in an array of continuous memory. Typically, lists
are created with an initial size. For example, the following code are created with an initial size. For example, the following code
constructs a QList with 200 elements: constructs a QList with 200 elements:
@ -82,17 +82,17 @@
The elements are automatically initialized with a The elements are automatically initialized with a
\l{default-constructed value}. If you want to initialize the \l{default-constructed value}. If you want to initialize the
vector with a different value, pass that value as the second list with a different value, pass that value as the second
argument to the constructor: argument to the constructor:
\snippet code/src_corelib_tools_qlist.cpp 2 \snippet code/src_corelib_tools_qlist.cpp 2
You can also call fill() at any time to fill the vector with a You can also call fill() at any time to fill the list with a
value. value.
QList uses 0-based indexes, just like C++ arrays. To access the QList uses 0-based indexes, just like C++ arrays. To access the
item at a particular index position, you can use operator[](). On item at a particular index position, you can use operator[](). On
non-const vectors, operator[]() returns a reference to the item non-const lists, operator[]() returns a reference to the item
that can be used on the left side of an assignment: that can be used on the left side of an assignment:
\snippet code/src_corelib_tools_qlist.cpp 3 \snippet code/src_corelib_tools_qlist.cpp 3
@ -106,34 +106,34 @@
Another way to access the data stored in a QList is to call Another way to access the data stored in a QList is to call
data(). The function returns a pointer to the first item in the data(). The function returns a pointer to the first item in the
vector. You can use the pointer to directly access and modify the list. You can use the pointer to directly access and modify the
elements stored in the vector. The pointer is also useful if you elements stored in the list. The pointer is also useful if you
need to pass a QList to a function that accepts a plain C++ need to pass a QList to a function that accepts a plain C++
array. array.
If you want to find all occurrences of a particular value in a If you want to find all occurrences of a particular value in a
vector, use indexOf() or lastIndexOf(). The former searches list, use indexOf() or lastIndexOf(). The former searches
forward starting from a given index position, the latter searches forward starting from a given index position, the latter searches
backward. Both return the index of the matching item if they found backward. Both return the index of the matching item if they found
one; otherwise, they return -1. For example: one; otherwise, they return -1. For example:
\snippet code/src_corelib_tools_qlist.cpp 5 \snippet code/src_corelib_tools_qlist.cpp 5
If you simply want to check whether a vector contains a If you simply want to check whether a list contains a
particular value, use contains(). If you want to find out how particular value, use contains(). If you want to find out how
many times a particular value occurs in the vector, use count(). many times a particular value occurs in the list, use count().
QList provides these basic functions to add, move, and remove QList provides these basic functions to add, move, and remove
items: insert(), replace(), remove(), prepend(), append(). With items: insert(), replace(), remove(), prepend(), append(). With
the exception of append() and replace(), these functions can be slow the exception of append() and replace(), these functions can be slow
(\l{linear time}) for large vectors, because they require moving many (\l{linear time}) for large lists, because they require moving many
items in the vector by one position in memory. If you want a container items in the list by one position in memory. If you want a container
class that provides fast insertion/removal in the middle, use class that provides fast insertion/removal in the middle, use
std::list instead. std::list instead.
Unlike plain C++ arrays, QLists can be resized at any time by Unlike plain C++ arrays, QLists can be resized at any time by
calling resize(). If the new size is larger than the old size, calling resize(). If the new size is larger than the old size,
QList might need to reallocate the whole vector. QList tries QList might need to reallocate the whole list. QList tries
to reduce the number of reallocations by preallocating up to twice to reduce the number of reallocations by preallocating up to twice
as much memory as the actual data needs. as much memory as the actual data needs.
@ -155,7 +155,7 @@
per-function basis. per-function basis.
Like the other container classes, QList provides \l{Java-style Like the other container classes, QList provides \l{Java-style
iterators} (QListIterator and QMutableVectorIterator) and iterators} (QListIterator and QMutableListIterator) and
\l{STL-style iterators} (QList::const_iterator and \l{STL-style iterators} (QList::const_iterator and
QList::iterator). In practice, these are rarely used, because QList::iterator). In practice, these are rarely used, because
you can use indexes into the QList. you can use indexes into the QList.
@ -195,7 +195,7 @@
/*! /*!
\fn template <typename T> QList<T> QList<T>::mid(int pos, int length = -1) const \fn template <typename T> QList<T> QList<T>::mid(int pos, int length = -1) const
Returns a sub-vector which contains elements from this vector, Returns a sub-list which contains elements from this list,
starting at position \a pos. If \a length is -1 (the default), all starting at position \a pos. If \a length is -1 (the default), all
elements after \a pos are included; otherwise \a length elements (or elements after \a pos are included; otherwise \a length elements (or
all remaining elements if there are less than \a length elements) all remaining elements if there are less than \a length elements)
@ -205,7 +205,7 @@
/*! \fn template <typename T> QList<T>::QList() /*! \fn template <typename T> QList<T>::QList()
Constructs an empty vector. Constructs an empty list.
\sa resize() \sa resize()
*/ */
@ -221,7 +221,7 @@
/*! \fn template <typename T> QList<T>::QList(int size) /*! \fn template <typename T> QList<T>::QList(int size)
Constructs a vector with an initial size of \a size elements. Constructs a list with an initial size of \a size elements.
The elements are initialized with a \l{default-constructed The elements are initialized with a \l{default-constructed
value}. value}.
@ -231,7 +231,7 @@
/*! \fn template <typename T> QList<T>::QList(int size, const T &value) /*! \fn template <typename T> QList<T>::QList(int size, const T &value)
Constructs a vector with an initial size of \a size elements. Constructs a list with an initial size of \a size elements.
Each element is initialized with \a value. Each element is initialized with \a value.
\sa resize(), fill() \sa resize(), fill()
@ -253,7 +253,7 @@
/*! \fn template <typename T> QList<T>::QList(std::initializer_list<T> args) /*! \fn template <typename T> QList<T>::QList(std::initializer_list<T> args)
\since 4.8 \since 4.8
Constructs a vector from the std::initializer_list given by \a args. Constructs a list from the std::initializer_list given by \a args.
This constructor is only enabled if the compiler supports C++11 initializer This constructor is only enabled if the compiler supports C++11 initializer
lists. lists.
@ -262,7 +262,7 @@
/*! \fn template <typename T> template<typename InputIterator> QList<T>::QList(InputIterator first, InputIterator last) /*! \fn template <typename T> template<typename InputIterator> QList<T>::QList(InputIterator first, InputIterator last)
\since 5.14 \since 5.14
Constructs a vector with the contents in the iterator range [\a first, \a last). Constructs a list with the contents in the iterator range [\a first, \a last).
The value type of \c InputIterator must be convertible to \c T. The value type of \c InputIterator must be convertible to \c T.
*/ */
@ -279,8 +279,8 @@
/*! \fn template <typename T> QList<T> &QList<T>::operator=(const QList<T> &other) /*! \fn template <typename T> QList<T> &QList<T>::operator=(const QList<T> &other)
Assigns \a other to this vector and returns a reference to this Assigns \a other to this list and returns a reference to this
vector. list.
*/ */
/*! /*!
@ -305,7 +305,7 @@
/*! \fn template <typename T> void QList<T>::swap(QList<T> &other) /*! \fn template <typename T> void QList<T>::swap(QList<T> &other)
\since 4.8 \since 4.8
Swaps vector \a other with this vector. This operation is very fast and Swaps list \a other with this list. This operation is very fast and
never fails. never fails.
*/ */
@ -321,10 +321,10 @@
/*! \fn template <typename T> bool QList<T>::operator==(const QList<T> &other) const /*! \fn template <typename T> bool QList<T>::operator==(const QList<T> &other) const
Returns \c true if \a other is equal to this vector; otherwise Returns \c true if \a other is equal to this list; otherwise
returns \c false. returns \c false.
Two vectors are considered equal if they contain the same values Two lists are considered equal if they contain the same values
in the same order. in the same order.
This function requires the value type to have an implementation This function requires the value type to have an implementation
@ -335,10 +335,10 @@
/*! \fn template <typename T> bool QList<T>::operator!=(const QList<T> &other) const /*! \fn template <typename T> bool QList<T>::operator!=(const QList<T> &other) const
Returns \c true if \a other is not equal to this vector; otherwise Returns \c true if \a other is not equal to this list; otherwise
returns \c false. returns \c false.
Two vectors are considered equal if they contain the same values Two lists are considered equal if they contain the same values
in the same order. in the same order.
This function requires the value type to have an implementation This function requires the value type to have an implementation
@ -351,7 +351,7 @@
\since 5.6 \since 5.6
\relates QList \relates QList
Returns \c true if vector \a lhs is Returns \c true if list \a lhs is
\l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
{lexicographically less than} \a rhs; otherwise returns \c false. {lexicographically less than} \a rhs; otherwise returns \c false.
@ -363,7 +363,7 @@
\since 5.6 \since 5.6
\relates QList \relates QList
Returns \c true if vector \a lhs is Returns \c true if list \a lhs is
\l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
{lexicographically less than or equal to} \a rhs; otherwise returns \c false. {lexicographically less than or equal to} \a rhs; otherwise returns \c false.
@ -375,7 +375,7 @@
\since 5.6 \since 5.6
\relates QList \relates QList
Returns \c true if vector \a lhs is Returns \c true if list \a lhs is
\l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
{lexicographically greater than} \a rhs; otherwise returns \c false. {lexicographically greater than} \a rhs; otherwise returns \c false.
@ -387,7 +387,7 @@
\since 5.6 \since 5.6
\relates QList \relates QList
Returns \c true if vector \a lhs is Returns \c true if list \a lhs is
\l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare} \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
{lexicographically greater than or equal to} \a rhs; otherwise returns \c false. {lexicographically greater than or equal to} \a rhs; otherwise returns \c false.
@ -408,21 +408,21 @@
/*! \fn template <typename T> int QList<T>::size() const /*! \fn template <typename T> int QList<T>::size() const
Returns the number of items in the vector. Returns the number of items in the list.
\sa isEmpty(), resize() \sa isEmpty(), resize()
*/ */
/*! \fn template <typename T> bool QList<T>::isEmpty() const /*! \fn template <typename T> bool QList<T>::isEmpty() const
Returns \c true if the vector has size 0; otherwise returns \c false. Returns \c true if the list has size 0; otherwise returns \c false.
\sa size(), resize() \sa size(), resize()
*/ */
/*! \fn template <typename T> void QList<T>::resize(int size) /*! \fn template <typename T> void QList<T>::resize(int size)
Sets the size of the vector to \a size. If \a size is greater than the Sets the size of the list to \a size. If \a size is greater than the
current size, elements are added to the end; the new elements are current size, elements are added to the end; the new elements are
initialized with a \l{default-constructed value}. If \a size is less initialized with a \l{default-constructed value}. If \a size is less
than the current size, elements are removed from the end. than the current size, elements are removed from the end.
@ -436,14 +436,14 @@
/*! \fn template <typename T> int QList<T>::capacity() const /*! \fn template <typename T> int QList<T>::capacity() const
Returns the maximum number of items that can be stored in the Returns the maximum number of items that can be stored in the
vector without forcing a reallocation. list without forcing a reallocation.
The sole purpose of this function is to provide a means of fine The sole purpose of this function is to provide a means of fine
tuning QList's memory usage. In general, you will rarely ever tuning QList's memory usage. In general, you will rarely ever
need to call this function. If you want to know how many items are need to call this function. If you want to know how many items are
in the vector, call size(). in the list, call size().
\note a statically allocated vector will report a capacity of 0, \note a statically allocated list will report a capacity of 0,
even if it's not empty. even if it's not empty.
\sa reserve(), squeeze() \sa reserve(), squeeze()
@ -452,7 +452,7 @@
/*! \fn template <typename T> void QList<T>::reserve(int size) /*! \fn template <typename T> void QList<T>::reserve(int size)
Attempts to allocate memory for at least \a size elements. If you Attempts to allocate memory for at least \a size elements. If you
know in advance how large the vector will be, you should call this know in advance how large the list will be, you should call this
function to prevent reallocations and memory fragmentation. function to prevent reallocations and memory fragmentation.
If \a size is an underestimate, the worst that will happen is that If \a size is an underestimate, the worst that will happen is that
@ -507,16 +507,16 @@
/*! \fn template <typename T> T *QList<T>::data() /*! \fn template <typename T> T *QList<T>::data()
Returns a pointer to the data stored in the vector. The pointer Returns a pointer to the data stored in the list. The pointer
can be used to access and modify the items in the vector. can be used to access and modify the items in the list.
Example: Example:
\snippet code/src_corelib_tools_qlist.cpp 6 \snippet code/src_corelib_tools_qlist.cpp 6
The pointer remains valid as long as the vector isn't The pointer remains valid as long as the list isn't
reallocated. reallocated.
This function is mostly useful to pass a vector to a function This function is mostly useful to pass a list to a function
that accepts a plain C++ array. that accepts a plain C++ array.
\sa constData(), operator[]() \sa constData(), operator[]()
@ -529,12 +529,12 @@
/*! \fn template <typename T> const T *QList<T>::constData() const /*! \fn template <typename T> const T *QList<T>::constData() const
Returns a const pointer to the data stored in the vector. The Returns a const pointer to the data stored in the list. The
pointer can be used to access the items in the vector. pointer can be used to access the items in the list.
The pointer remains valid as long as the vector isn't The pointer remains valid as long as the list isn't
reallocated. reallocated.
This function is mostly useful to pass a vector to a function This function is mostly useful to pass a list to a function
that accepts a plain C++ array. that accepts a plain C++ array.
\sa data(), operator[]() \sa data(), operator[]()
@ -542,11 +542,11 @@
/*! \fn template <typename T> void QList<T>::clear() /*! \fn template <typename T> void QList<T>::clear()
Removes all the elements from the vector. Removes all the elements from the list.
\note Until Qt 5.6, this also released the memory used by \note Until Qt 5.6, this also released the memory used by
the vector. From Qt 5.7, the capacity is preserved. To shed the list. From Qt 5.7, the capacity is preserved. To shed
all capacity, swap with a default-constructed vector: all capacity, swap with a default-constructed list:
\code \code
QList<T> v ...; QList<T> v ...;
QList<T>().swap(v); QList<T>().swap(v);
@ -559,9 +559,9 @@
/*! \fn template <typename T> const T &QList<T>::at(int i) const /*! \fn template <typename T> const T &QList<T>::at(int i) const
Returns the item at index position \a i in the vector. Returns the item at index position \a i in the list.
\a i must be a valid index position in the vector (i.e., 0 <= \a \a i must be a valid index position in the list (i.e., 0 <= \a
i < size()). i < size()).
\sa value(), operator[]() \sa value(), operator[]()
@ -571,7 +571,7 @@
Returns the item at index position \a i as a modifiable reference. Returns the item at index position \a i as a modifiable reference.
\a i must be a valid index position in the vector (i.e., 0 <= \a i \a i must be a valid index position in the list (i.e., 0 <= \a i
< size()). < size()).
Note that using non-const operators can cause QList to do a deep Note that using non-const operators can cause QList to do a deep
@ -590,17 +590,17 @@
/*! /*!
\fn template <typename T> void QList<T>::append(const T &value) \fn template <typename T> void QList<T>::append(const T &value)
Inserts \a value at the end of the vector. Inserts \a value at the end of the list.
Example: Example:
\snippet code/src_corelib_tools_qlist.cpp 7 \snippet code/src_corelib_tools_qlist.cpp 7
This is the same as calling resize(size() + 1) and assigning \a This is the same as calling resize(size() + 1) and assigning \a
value to the new last element in the vector. value to the new last element in the list.
This operation is relatively fast, because QList typically This operation is relatively fast, because QList typically
allocates more memory than necessary, so it can grow without allocates more memory than necessary, so it can grow without
reallocating the entire vector each time. reallocating the entire list each time.
\sa operator<<(), prepend(), insert() \sa operator<<(), prepend(), insert()
*/ */
@ -621,7 +621,7 @@
\since 5.5 \since 5.5
Appends the items of the \a value vector to this vector. Appends the items of the \a value list to this list.
\sa operator<<(), operator+=() \sa operator<<(), operator+=()
*/ */
@ -631,15 +631,15 @@
\fn template <typename T> void QList<T>::prepend(const T &value) \fn template <typename T> void QList<T>::prepend(const T &value)
\fn template <typename T> void QList<T>::prepend(T &&value) \fn template <typename T> void QList<T>::prepend(T &&value)
Inserts \a value at the beginning of the vector. Inserts \a value at the beginning of the list.
Example: Example:
\snippet code/src_corelib_tools_qlist.cpp 8 \snippet code/src_corelib_tools_qlist.cpp 8
This is the same as vector.insert(0, \a value). This is the same as list.insert(0, \a value).
For large vectors, this operation can be slow (\l{linear time}), For large lists, this operation can be slow (\l{linear time}),
because it requires moving all the items in the vector by one because it requires moving all the items in the list by one
position further in memory. If you want a container class that position further in memory. If you want a container class that
provides a fast prepend operation, use std::list provides a fast prepend operation, use std::list
instead. instead.
@ -664,7 +664,7 @@
returned reference: returned reference:
\snippet code/src_corelib_tools_qlist.cpp emplace-back-ref \snippet code/src_corelib_tools_qlist.cpp emplace-back-ref
This is the same as vector.emplace(vector.size(), \a args). This is the same as list.emplace(list.size(), \a args).
\sa emplace \sa emplace
*/ */
@ -672,14 +672,14 @@
/*! \fn template <typename T> void QList<T>::insert(int i, const T &value) /*! \fn template <typename T> void QList<T>::insert(int i, const T &value)
\fn template <typename T> void QList<T>::insert(int i, T &&value) \fn template <typename T> void QList<T>::insert(int i, T &&value)
Inserts \a value at index position \a i in the vector. If \a i is Inserts \a value at index position \a i in the list. If \a i is
0, the value is prepended to the vector. If \a i is size(), the 0, the value is prepended to the list. If \a i is size(), the
value is appended to the vector. value is appended to the list.
Example: Example:
\snippet code/src_corelib_tools_qlist.cpp 9 \snippet code/src_corelib_tools_qlist.cpp 9
For large vectors, this operation can be slow (\l{linear time}), For large lists, this operation can be slow (\l{linear time}),
because it requires moving all the items at indexes \a i and because it requires moving all the items at indexes \a i and
above by one position further in memory. If you want a container above by one position further in memory. If you want a container
class that provides a fast insert() function, use std::list class that provides a fast insert() function, use std::list
@ -693,7 +693,7 @@
\overload \overload
Inserts \a count copies of \a value at index position \a i in the Inserts \a count copies of \a value at index position \a i in the
vector. list.
Example: Example:
\snippet code/src_corelib_tools_qlist.cpp 10 \snippet code/src_corelib_tools_qlist.cpp 10
@ -740,7 +740,7 @@
Replaces the item at index position \a i with \a value. Replaces the item at index position \a i with \a value.
\a i must be a valid index position in the vector (i.e., 0 <= \a \a i must be a valid index position in the list (i.e., 0 <= \a
i < size()). i < size()).
\sa operator[](), remove() \sa operator[](), remove()
@ -759,7 +759,7 @@
\overload \overload
Removes \a count elements from the middle of the vector, starting at Removes \a count elements from the middle of the list, starting at
index position \a i. index position \a i.
\sa insert(), replace(), fill() \sa insert(), replace(), fill()
@ -783,7 +783,7 @@
\since 5.4 \since 5.4
Removes all elements that compare equal to \a t from the Removes all elements that compare equal to \a t from the
vector. Returns the number of elements removed, if any. list. Returns the number of elements removed, if any.
Provided for compatibility with QList. Provided for compatibility with QList.
@ -794,7 +794,7 @@
\since 5.4 \since 5.4
Removes the first element that compares equal to \a t from the Removes the first element that compares equal to \a t from the
vector. Returns whether an element was, in fact, removed. list. Returns whether an element was, in fact, removed.
Provided for compatibility with QList. Provided for compatibility with QList.
@ -840,9 +840,9 @@
/*! \fn template <typename T> void QList<T>::removeFirst() /*! \fn template <typename T> void QList<T>::removeFirst()
\since 5.1 \since 5.1
Removes the first item in the vector. Calling this function is Removes the first item in the list. Calling this function is
equivalent to calling remove(0). The vector must not be empty. If equivalent to calling remove(0). The list must not be empty. If
the vector can be empty, call isEmpty() before calling this the list can be empty, call isEmpty() before calling this
function. function.
\sa remove(), takeFirst(), isEmpty() \sa remove(), takeFirst(), isEmpty()
@ -850,9 +850,9 @@
/*! \fn template <typename T> void QList<T>::removeLast() /*! \fn template <typename T> void QList<T>::removeLast()
\since 5.1 \since 5.1
Removes the last item in the vector. Calling this function is Removes the last item in the list. Calling this function is
equivalent to calling remove(size() - 1). The vector must not be equivalent to calling remove(size() - 1). The list must not be
empty. If the vector can be empty, call isEmpty() before calling empty. If the list can be empty, call isEmpty() before calling
this function. this function.
\sa remove(), takeLast(), removeFirst(), isEmpty() \sa remove(), takeLast(), removeFirst(), isEmpty()
@ -861,8 +861,8 @@
/*! \fn template <typename T> T QList<T>::takeFirst() /*! \fn template <typename T> T QList<T>::takeFirst()
\since 5.1 \since 5.1
Removes the first item in the vector and returns it. This function Removes the first item in the list and returns it. This function
assumes the vector is not empty. To avoid failure, call isEmpty() assumes the list is not empty. To avoid failure, call isEmpty()
before calling this function. before calling this function.
\sa takeLast(), removeFirst() \sa takeLast(), removeFirst()
@ -872,7 +872,7 @@
\since 5.1 \since 5.1
Removes the last item in the list and returns it. This function Removes the last item in the list and returns it. This function
assumes the vector is not empty. To avoid failure, call isEmpty() assumes the list is not empty. To avoid failure, call isEmpty()
before calling this function. before calling this function.
If you don't use the return value, removeLast() is more If you don't use the return value, removeLast() is more
@ -895,8 +895,8 @@
/*! \fn template <typename T> QList<T> &QList<T>::fill(const T &value, int size = -1) /*! \fn template <typename T> QList<T> &QList<T>::fill(const T &value, int size = -1)
Assigns \a value to all items in the vector. If \a size is Assigns \a value to all items in the list. If \a size is
different from -1 (the default), the vector is resized to size \a different from -1 (the default), the list is resized to size \a
size beforehand. size beforehand.
Example: Example:
@ -908,7 +908,7 @@
/*! \fn template <typename T> int QList<T>::indexOf(const T &value, int from = 0) const /*! \fn template <typename T> int QList<T>::indexOf(const T &value, int from = 0) const
Returns the index position of the first occurrence of \a value in Returns the index position of the first occurrence of \a value in
the vector, searching forward from index position \a from. the list, searching forward from index position \a from.
Returns -1 if no item matched. Returns -1 if no item matched.
Example: Example:
@ -923,7 +923,7 @@
/*! \fn template <typename T> int QList<T>::lastIndexOf(const T &value, int from = -1) const /*! \fn template <typename T> int QList<T>::lastIndexOf(const T &value, int from = -1) const
Returns the index position of the last occurrence of the value \a Returns the index position of the last occurrence of the value \a
value in the vector, searching backward from index position \a value in the list, searching backward from index position \a
from. If \a from is -1 (the default), the search starts at the from. If \a from is -1 (the default), the search starts at the
last item. Returns -1 if no item matched. last item. Returns -1 if no item matched.
@ -938,7 +938,7 @@
/*! \fn template <typename T> bool QList<T>::contains(const T &value) const /*! \fn template <typename T> bool QList<T>::contains(const T &value) const
Returns \c true if the vector contains an occurrence of \a value; Returns \c true if the list contains an occurrence of \a value;
otherwise returns \c false. otherwise returns \c false.
This function requires the value type to have an implementation of This function requires the value type to have an implementation of
@ -950,7 +950,7 @@
/*! \fn template <typename T> bool QList<T>::startsWith(const T &value) const /*! \fn template <typename T> bool QList<T>::startsWith(const T &value) const
\since 4.5 \since 4.5
Returns \c true if this vector is not empty and its first Returns \c true if this list is not empty and its first
item is equal to \a value; otherwise returns \c false. item is equal to \a value; otherwise returns \c false.
\sa isEmpty(), first() \sa isEmpty(), first()
@ -959,7 +959,7 @@
/*! \fn template <typename T> bool QList<T>::endsWith(const T &value) const /*! \fn template <typename T> bool QList<T>::endsWith(const T &value) const
\since 4.5 \since 4.5
Returns \c true if this vector is not empty and its last Returns \c true if this list is not empty and its last
item is equal to \a value; otherwise returns \c false. item is equal to \a value; otherwise returns \c false.
\sa isEmpty(), last() \sa isEmpty(), last()
@ -968,7 +968,7 @@
/*! \fn template <typename T> int QList<T>::count(const T &value) const /*! \fn template <typename T> int QList<T>::count(const T &value) const
Returns the number of occurrences of \a value in the vector. Returns the number of occurrences of \a value in the list.
This function requires the value type to have an implementation of This function requires the value type to have an implementation of
\c operator==(). \c operator==().
@ -985,8 +985,8 @@
/*! \fn template <typename T> QList<T>::iterator QList<T>::begin() /*! \fn template <typename T> QList<T>::iterator QList<T>::begin()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in Returns an \l{STL-style iterators}{STL-style iterator} pointing to the
the vector. first item in the list.
\sa constBegin(), end() \sa constBegin(), end()
*/ */
@ -1000,7 +1000,7 @@
\since 5.0 \since 5.0
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
in the vector. in the list.
\sa begin(), cend() \sa begin(), cend()
*/ */
@ -1008,7 +1008,7 @@
/*! \fn template <typename T> QList<T>::const_iterator QList<T>::constBegin() const /*! \fn template <typename T> QList<T>::const_iterator QList<T>::constBegin() const
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
in the vector. in the list.
\sa begin(), constEnd() \sa begin(), constEnd()
*/ */
@ -1016,7 +1016,7 @@
/*! \fn template <typename T> QList<T>::iterator QList<T>::end() /*! \fn template <typename T> QList<T>::iterator QList<T>::end()
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item
after the last item in the vector. after the last item in the list.
\sa begin(), constEnd() \sa begin(), constEnd()
*/ */
@ -1030,7 +1030,7 @@
\since 5.0 \since 5.0
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
item after the last item in the vector. item after the last item in the list.
\sa cbegin(), end() \sa cbegin(), end()
*/ */
@ -1038,7 +1038,7 @@
/*! \fn template <typename T> QList<T>::const_iterator QList<T>::constEnd() const /*! \fn template <typename T> QList<T>::const_iterator QList<T>::constEnd() const
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
item after the last item in the vector. item after the last item in the list.
\sa constBegin(), end() \sa constBegin(), end()
*/ */
@ -1047,7 +1047,7 @@
\since 5.6 \since 5.6
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
item in the vector, in reverse order. item in the list, in reverse order.
\sa begin(), crbegin(), rend() \sa begin(), crbegin(), rend()
*/ */
@ -1061,7 +1061,7 @@
\since 5.6 \since 5.6
Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
item in the vector, in reverse order. item in the list, in reverse order.
\sa begin(), rbegin(), rend() \sa begin(), rbegin(), rend()
*/ */
@ -1070,7 +1070,7 @@
\since 5.6 \since 5.6
Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past
the last item in the vector, in reverse order. the last item in the list, in reverse order.
\sa end(), crend(), rbegin() \sa end(), crend(), rbegin()
*/ */
@ -1084,7 +1084,7 @@
\since 5.6 \since 5.6
Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to one Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to one
past the last item in the vector, in reverse order. past the last item in the list, in reverse order.
\sa end(), rend(), rbegin() \sa end(), rend(), rbegin()
*/ */
@ -1092,7 +1092,7 @@
/*! \fn template <typename T> QList<T>::iterator QList<T>::erase(iterator pos) /*! \fn template <typename T> QList<T>::iterator QList<T>::erase(iterator pos)
Removes the item pointed to by the iterator \a pos from the Removes the item pointed to by the iterator \a pos from the
vector, and returns an iterator to the next item in the vector list, and returns an iterator to the next item in the list
(which may be end()). (which may be end()).
\sa insert(), remove() \sa insert(), remove()
@ -1109,8 +1109,8 @@
/*! \fn template <typename T> T& QList<T>::first() /*! \fn template <typename T> T& QList<T>::first()
Returns a reference to the first item in the vector. This Returns a reference to the first item in the list. This
function assumes that the vector isn't empty. function assumes that the list isn't empty.
\sa last(), isEmpty(), constFirst() \sa last(), isEmpty(), constFirst()
*/ */
@ -1123,16 +1123,16 @@
/*! \fn template <typename T> const T& QList<T>::constFirst() const /*! \fn template <typename T> const T& QList<T>::constFirst() const
\since 5.6 \since 5.6
Returns a const reference to the first item in the vector. This Returns a const reference to the first item in the list. This
function assumes that the vector isn't empty. function assumes that the list isn't empty.
\sa constLast(), isEmpty(), first() \sa constLast(), isEmpty(), first()
*/ */
/*! \fn template <typename T> T& QList<T>::last() /*! \fn template <typename T> T& QList<T>::last()
Returns a reference to the last item in the vector. This function Returns a reference to the last item in the list. This function
assumes that the vector isn't empty. assumes that the list isn't empty.
\sa first(), isEmpty(), constLast() \sa first(), isEmpty(), constLast()
*/ */
@ -1145,15 +1145,15 @@
/*! \fn template <typename T> const T& QList<T>::constLast() const /*! \fn template <typename T> const T& QList<T>::constLast() const
\since 5.6 \since 5.6
Returns a const reference to the last item in the vector. This function Returns a const reference to the last item in the list. This function
assumes that the vector isn't empty. assumes that the list isn't empty.
\sa constFirst(), isEmpty(), last() \sa constFirst(), isEmpty(), last()
*/ */
/*! \fn template <typename T> T QList<T>::value(int i) const /*! \fn template <typename T> T QList<T>::value(int i) const
Returns the value at index position \a i in the vector. Returns the value at index position \a i in the list.
If the index \a i is out of bounds, the function returns If the index \a i is out of bounds, the function returns
a \l{default-constructed value}. If you are certain that a \l{default-constructed value}. If you are certain that
@ -1234,14 +1234,14 @@
/*! \fn template <typename T> bool QList<T>::empty() const /*! \fn template <typename T> bool QList<T>::empty() const
This function is provided for STL compatibility. It is equivalent This function is provided for STL compatibility. It is equivalent
to isEmpty(), returning \c true if the vector is empty; otherwise to isEmpty(), returning \c true if the list is empty; otherwise
returns \c false. returns \c false.
*/ */
/*! \fn template <typename T> QList<T> &QList<T>::operator+=(const QList<T> &other) /*! \fn template <typename T> QList<T> &QList<T>::operator+=(const QList<T> &other)
Appends the items of the \a other vector to this vector and Appends the items of the \a other list to this list and
returns a reference to this vector. returns a reference to this list.
\sa operator+(), append() \sa operator+(), append()
*/ */
@ -1250,7 +1250,7 @@
\overload \overload
Appends \a value to the vector. Appends \a value to the list.
\sa append(), operator<<() \sa append(), operator<<()
*/ */
@ -1265,16 +1265,15 @@
/*! \fn template <typename T> QList<T> QList<T>::operator+(const QList<T> &other) const /*! \fn template <typename T> QList<T> QList<T>::operator+(const QList<T> &other) const
Returns a vector that contains all the items in this vector Returns a list that contains all the items in this list
followed by all the items in the \a other vector. followed by all the items in the \a other list.
\sa operator+=() \sa operator+=()
*/ */
/*! \fn template <typename T> QList<T> &QList<T>::operator<<(const T &value) /*! \fn template <typename T> QList<T> &QList<T>::operator<<(const T &value)
Appends \a value to the vector and returns a reference to this Appends \a value to the list and returns a reference to this list.
vector.
\sa append(), operator+=() \sa append(), operator+=()
*/ */
@ -1290,8 +1289,7 @@
/*! \fn template <typename T> QList<T> &QList<T>::operator<<(const QList<T> &other) /*! \fn template <typename T> QList<T> &QList<T>::operator<<(const QList<T> &other)
Appends \a other to the vector and returns a reference to the Appends \a other to the list and returns a reference to the list.
vector.
*/ */
/*! \typedef QList::iterator /*! \typedef QList::iterator
@ -1308,7 +1306,7 @@
while iterators are active on that container. For more information, while iterators are active on that container. For more information,
read \l{Implicit sharing iterator problem}. read \l{Implicit sharing iterator problem}.
\sa QList::begin(), QList::end(), QList::const_iterator, QMutableVectorIterator \sa QList::begin(), QList::end(), QList::const_iterator, QMutableListIterator
*/ */
/*! \typedef QList::const_iterator /*! \typedef QList::const_iterator
@ -1451,20 +1449,20 @@
\sa fromStdVector(), QList::toStdList() \sa fromStdVector(), QList::toStdList()
*/ */
/*! \fn template <typename T> QDataStream &operator<<(QDataStream &out, const QList<T> &vector) /*! \fn template <typename T> QDataStream &operator<<(QDataStream &out, const QList<T> &list)
\relates QList \relates QList
Writes the vector \a vector to stream \a out. Writes the list \a list to stream \a out.
This function requires the value type to implement \c operator<<(). This function requires the value type to implement \c operator<<().
\sa{Serializing Qt Data Types}{Format of the QDataStream operators} \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
*/ */
/*! \fn template <typename T> QDataStream &operator>>(QDataStream &in, QList<T> &vector) /*! \fn template <typename T> QDataStream &operator>>(QDataStream &in, QList<T> &list)
\relates QList \relates QList
Reads a vector from stream \a in into \a vector. Reads a list from stream \a in into \a list.
This function requires the value type to implement \c operator>>(). This function requires the value type to implement \c operator>>().

View File

@ -66,20 +66,20 @@
compiler won't let you, for example, store a QWidget as a value; compiler won't let you, for example, store a QWidget as a value;
instead, store a QWidget *. instead, store a QWidget *.
QVarLengthArray, like QVector, provides a resizable array data QVarLengthArray, like QList, provides a resizable array data
structure. The main differences between the two classes are: structure. The main differences between the two classes are:
\list \list
\li QVarLengthArray's API is much more low-level and it lacks \li QVarLengthArray's API is much more low-level and it lacks
some of QVector's functionality. some of QList's functionality.
\li QVarLengthArray doesn't initialize the memory if the value is \li QVarLengthArray doesn't initialize the memory if the value is
a basic type. (QVector always does.) a basic type. (QList always does.)
\li QVector uses \l{implicit sharing} as a memory optimization. \li QList uses \l{implicit sharing} as a memory optimization.
QVarLengthArray doesn't provide that feature; however, it QVarLengthArray doesn't provide that feature; however, it
usually produces slightly better performance due to reduced usually produces slightly better performance due to reduced
overhead, especially in tight loops. overhead, especially in tight loops.
\endlist \endlist
In summary, QVarLengthArray is a low-level optimization class In summary, QVarLengthArray is a low-level optimization class
@ -87,7 +87,7 @@
places inside Qt and was added to Qt's public API for the places inside Qt and was added to Qt's public API for the
convenience of advanced users. convenience of advanced users.
\sa QVector, QList \sa QList
*/ */
/*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype size) /*! \fn template<class T, qsizetype Prealloc> QVarLengthArray<T, Prealloc>::QVarLengthArray(qsizetype size)

View File

@ -1084,7 +1084,7 @@ void tst_Collections::stack()
stack.push(1); stack.push(1);
stack.push(2); stack.push(2);
stack.push(3); stack.push(3);
QVectorIterator<int> i = stack; QListIterator<int> i = stack;
i.toBack(); i.toBack();
int sum = 0; int sum = 0;
while (i.hasPrevious()) while (i.hasPrevious())