summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/doc/snippets')
-rw-r--r--src/corelib/doc/snippets/code/doc_src_containers.cpp16
-rw-r--r--src/corelib/doc/snippets/code/doc_src_properties.cpp2
-rw-r--r--src/corelib/doc/snippets/code/doc_src_qiterator.cpp71
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_io_qdebug.cpp5
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_serialization_qcborstream.cpp8
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp8
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qlinkedlist.cpp214
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp23
-rw-r--r--src/corelib/doc/snippets/qmetaobject-revision/window.h4
-rw-r--r--src/corelib/doc/snippets/qstring/main.cpp8
10 files changed, 46 insertions, 313 deletions
diff --git a/src/corelib/doc/snippets/code/doc_src_containers.cpp b/src/corelib/doc/snippets/code/doc_src_containers.cpp
index 84935580c9..9b23a9056c 100644
--- a/src/corelib/doc/snippets/code/doc_src_containers.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_containers.cpp
@@ -205,35 +205,35 @@ for (i = splitter->sizes().begin();
//! [15]
-QLinkedList<QString> list;
+QVector<QString> values;
...
QString str;
-foreach (str, list)
+foreach (str, values)
qDebug() << str;
//! [15]
//! [16]
-QLinkedList<QString> list;
+QVector<QString> values;
...
-QLinkedListIterator<QString> i(list);
+QVectorIterator<QString> i(values);
while (i.hasNext())
qDebug() << i.next();
//! [16]
//! [17]
-QLinkedList<QString> list;
+QVector<QString> values;
...
-foreach (const QString &str, list)
+foreach (const QString &str, values)
qDebug() << str;
//! [17]
//! [18]
-QLinkedList<QString> list;
+QVector<QString> values;
...
-foreach (const QString &str, list) {
+foreach (const QString &str, values) {
if (str.isEmpty())
break;
qDebug() << str;
diff --git a/src/corelib/doc/snippets/code/doc_src_properties.cpp b/src/corelib/doc/snippets/code/doc_src_properties.cpp
index a67945bbcf..e026a47e23 100644
--- a/src/corelib/doc/snippets/code/doc_src_properties.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_properties.cpp
@@ -54,7 +54,7 @@ Q_PROPERTY(type name
MEMBER memberName [(READ getFunction | WRITE setFunction)])
[RESET resetFunction]
[NOTIFY notifySignal]
- [REVISION int]
+ [REVISION int | REVISION(int[, int])]
[DESIGNABLE bool]
[SCRIPTABLE bool]
[STORED bool]
diff --git a/src/corelib/doc/snippets/code/doc_src_qiterator.cpp b/src/corelib/doc/snippets/code/doc_src_qiterator.cpp
index 58f4166c3e..0d0b864a83 100644
--- a/src/corelib/doc/snippets/code/doc_src_qiterator.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_qiterator.cpp
@@ -64,24 +64,6 @@ while (i.hasPrevious())
qDebug() << i.previous();
//! [1]
-
-//! [2]
-QLinkedList<float> list;
-...
-QLinkedListIterator<float> i(list);
-while (i.hasNext())
- qDebug() << i.next();
-//! [2]
-
-
-//! [3]
-QLinkedListIterator<float> i(list);
-i.toBack();
-while (i.hasPrevious())
- qDebug() << i.previous();
-//! [3]
-
-
//! [4]
QVector<float> vector;
...
@@ -145,37 +127,6 @@ while (i.hasNext()) {
}
//! [10]
-
-//! [11]
-QLinkedList<float> list;
-...
-QMutableLinkedListIterator<float> i(list);
-while (i.hasNext())
- qDebug() << i.next();
-//! [11]
-
-
-//! [12]
-QMutableLinkedListIterator<float> i(list);
-i.toBack();
-while (i.hasPrevious())
- qDebug() << i.previous();
-//! [12]
-
-
-//! [13]
-QMutableLinkedListIterator<int> i(list);
-while (i.hasNext()) {
- int val = i.next();
- if (val < 0) {
- i.setValue(-val);
- } else if (val == 0) {
- i.remove();
- }
-}
-//! [13]
-
-
//! [14]
QVector<float> vector;
...
@@ -184,7 +135,6 @@ while (i.hasNext())
qDebug() << i.next();
//! [14]
-
//! [15]
QMutableVectorIterator<float> i(vector);
i.toBack();
@@ -232,17 +182,6 @@ while (i.hasNext()) {
}
//! [19]
-
-//! [20]
-QMutableLinkedListIterator<int> i(list);
-while (i.hasNext()) {
- int val = i.next();
- if (val < -32768 || val > 32767)
- i.remove();
-}
-//! [20]
-
-
//! [21]
QMutableVectorIterator<int> i(vector);
while (i.hasNext()) {
@@ -271,16 +210,6 @@ while (i.hasNext()) {
}
//! [23]
-
-//! [24]
-QMutableLinkedListIterator<double> i(list);
-while (i.hasNext()) {
- double val = i.next();
- i.setValue(std::sqrt(val));
-}
-//! [24]
-
-
//! [25]
QMutableVectorIterator<double> i(list);
while (i.hasNext()) {
diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qdebug.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qdebug.cpp
index 14e72e99dd..5154dc5d68 100644
--- a/src/corelib/doc/snippets/code/src_corelib_io_qdebug.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_io_qdebug.cpp
@@ -93,3 +93,8 @@
ba = QByteArray("a\0b", 3);
qDebug() << ba // prints: "\a\x00""b"
//! [1]
+
+//! [toString]
+ QTRY_VERIFY2(list.isEmpty(), qPrintable(QString::fromLatin1(
+ "Expected list to be empty, but it has the following items: %1")).arg(QDebug::toString(list)));
+//! [toString]
diff --git a/src/corelib/doc/snippets/code/src_corelib_serialization_qcborstream.cpp b/src/corelib/doc/snippets/code/src_corelib_serialization_qcborstream.cpp
index 6ddb5a9365..973ae75847 100644
--- a/src/corelib/doc/snippets/code/src_corelib_serialization_qcborstream.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_serialization_qcborstream.cpp
@@ -208,10 +208,10 @@
//! [19]
//! [20]
- void appendList(QCborStreamWriter &writer, const QLinkedList<QString> &list)
+ void appendList(QCborStreamWriter &writer, const QVector<QString> &values)
{
writer.startArray();
- for (const QString &s : list)
+ for (const QString &s : values)
writer.append(s);
writer.endArray();
}
@@ -228,10 +228,10 @@
//! [21]
//! [22]
- void appendMap(QCborStreamWriter &writer, const QLinkedList<QPair<int, QString>> &list)
+ void appendMap(QCborStreamWriter &writer, const QVector<QPair<int, QString>> &values)
{
writer.startMap();
- for (const auto pair : list) {
+ for (const auto pair : values) {
writer.append(pair.first)
writer.append(pair.second);
}
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp
index 01f620cf08..9c07a2e92c 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qbytearray.cpp
@@ -372,16 +372,13 @@ a = str.toFloat(&ok); // a == 0, ok == false
//! [39]
QByteArray text("Qt is great!");
text.toBase64(); // returns "UXQgaXMgZ3JlYXQh"
-//! [39]
-//! [39bis]
QByteArray text("<p>Hello?</p>");
text.toBase64(QByteArray::Base64Encoding | QByteArray::OmitTrailingEquals); // returns "PHA+SGVsbG8/PC9wPg"
text.toBase64(QByteArray::Base64Encoding); // returns "PHA+SGVsbG8/PC9wPg=="
text.toBase64(QByteArray::Base64UrlEncoding); // returns "PHA-SGVsbG8_PC9wPg=="
text.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals); // returns "PHA-SGVsbG8_PC9wPg"
-//! [39bis]
-
+//! [39]
//! [40]
QByteArray ba;
@@ -422,9 +419,7 @@ QDataStream in(&data, QIODevice::ReadOnly);
//! [44]
QByteArray text = QByteArray::fromBase64("UXQgaXMgZ3JlYXQh");
text.data(); // returns "Qt is great!"
-//! [44]
-//! [44bis]
QByteArray::fromBase64("PHA+SGVsbG8/PC9wPg==", QByteArray::Base64Encoding); // returns "<p>Hello?</p>"
QByteArray::fromBase64("PHA-SGVsbG8_PC9wPg==", QByteArray::Base64UrlEncoding); // returns "<p>Hello?</p>"
//! [44bis]
@@ -442,7 +437,6 @@ if (result.decodingStatus == QByteArray::Base64DecodingStatus::Ok)
process(result.decoded);
//! [44quater]
-
//! [45]
QByteArray text = QByteArray::fromHex("517420697320677265617421");
text.data(); // returns "Qt is great!"
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qlinkedlist.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qlinkedlist.cpp
deleted file mode 100644
index e8754a5f34..0000000000
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qlinkedlist.cpp
+++ /dev/null
@@ -1,214 +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]
-QLinkedList<int> integerList;
-QLinkedList<QTime> timeList;
-//! [0]
-
-
-//! [1]
-QLinkedList<QString> list;
-list << "one" << "two" << "three";
-// list: ["one", "two", "three"]
-//! [1]
-
-
-//! [2]
-QLinkedList<QWidget *> list;
-...
-while (!list.isEmpty())
- delete list.takeFirst();
-//! [2]
-
-
-//! [3]
-QLinkedList<QString> list;
-list.append("one");
-list.append("two");
-list.append("three");
-// list: ["one", "two", "three"]
-//! [3]
-
-
-//! [4]
-QLinkedList<QString> list;
-list.prepend("one");
-list.prepend("two");
-list.prepend("three");
-// list: ["three", "two", "one"]
-//! [4]
-
-
-//! [5]
-QList<QString> list;
-list << "sun" << "cloud" << "sun" << "rain";
-list.removeAll("sun");
-// list: ["cloud", "rain"]
-//! [5]
-
-
-//! [6]
-QList<QString> list;
-list << "sun" << "cloud" << "sun" << "rain";
-list.removeOne("sun");
-// list: ["cloud", "sun", "rain"]
-//! [6]
-
-
-//! [7]
-QLinkedList<QString> list;
-list.append("January");
-list.append("February");
-...
-list.append("December");
-
-QLinkedList<QString>::iterator i;
-for (i = list.begin(); i != list.end(); ++i)
- cout << *i << Qt::endl;
-//! [7]
-
-
-//! [8]
-QLinkedList<QString> list;
-...
-QLinkedList<QString>::iterator it = std::find(list.begin(),
- list.end(), "Joel");
-if (it != list.end())
- cout << "Found Joel" << Qt::endl;
-//! [8]
-
-
-//! [9]
-QLinkedList<int>::iterator i;
-for (i = list.begin(); i != list.end(); ++i)
- *i += 2;
-//! [9]
-
-
-//! [10]
-QLinkedList<QString> list;
-...
-QLinkedList<QString>::iterator i = list.begin();
-while (i != list.end()) {
- if ((*i).startsWith('_'))
- i = list.erase(i);
- else
- ++i;
-}
-//! [10]
-
-
-//! [11]
-QLinkedList<QString>::iterator i = list.begin();
-while (i != list.end()) {
- QLinkedList<QString>::iterator previous = i;
- ++i;
- if ((*previous).startsWith('_'))
- list.erase(previous);
-}
-//! [11]
-
-
-//! [12]
-// WRONG
-while (i != list.end()) {
- if ((*i).startsWith('_'))
- list.erase(i);
- ++i;
-}
-//! [12]
-
-
-//! [13]
-if (*it == "Hello")
- *it = "Bonjour";
-//! [13]
-
-
-//! [14]
-QLinkedList<QString> list;
-list.append("January");
-list.append("February");
-...
-list.append("December");
-
-QLinkedList<QString>::const_iterator i;
-for (i = list.constBegin(); i != list.constEnd(); ++i)
- cout << *i << Qt::endl;
-//! [14]
-
-
-//! [15]
-QLinkedList<QString> list;
-...
-QLinkedList<QString>::const_iterator it = std::find(list.constBegin(),
- list.constEnd(), "Joel");
-if (it != list.constEnd())
- cout << "Found Joel" << Qt::endl;
-//! [15]
-
-
-//! [16]
-std::list<double> stdlist;
-list.push_back(1.2);
-list.push_back(0.5);
-list.push_back(3.14);
-
-QLinkedList<double> list = QLinkedList<double>::fromStdList(stdlist);
-//! [16]
-
-
-//! [17]
-QLinkedList<double> list;
-list << 1.2 << 0.5 << 3.14;
-
-std::list<double> stdlist = list.toStdList();
-//! [17]
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp
index a05233049f..76a8d68f64 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp
@@ -115,6 +115,29 @@ vector.append(std::move(three));
//! [move-append]
+//! [emplace]
+QVector<QString> vector{"a", "ccc"};
+vector.emplace(1, 2, 'b');
+// vector: ["a", "bb", "ccc"]
+//! [emplace]
+
+
+//! [emplace-back]
+QVector<QString> vector{"one", "two"};
+vector.emplaceBack(3, 'a');
+qDebug() << vector;
+// vector: ["one", "two", "aaa"]
+//! [emplace-back]
+
+
+//! [emplace-back-ref]
+QVector<QString> vector;
+auto &ref = vector.emplaceBack();
+ref = "one";
+// vector: ["one"]
+//! [emplace-back-ref]
+
+
//! [8]
QVector<QString> vector;
vector.prepend("one");
diff --git a/src/corelib/doc/snippets/qmetaobject-revision/window.h b/src/corelib/doc/snippets/qmetaobject-revision/window.h
index f93d253b6b..f519a6f2dc 100644
--- a/src/corelib/doc/snippets/qmetaobject-revision/window.h
+++ b/src/corelib/doc/snippets/qmetaobject-revision/window.h
@@ -58,7 +58,7 @@ class Window : public QWidget
{
Q_OBJECT
Q_PROPERTY(int normalProperty READ normalProperty)
- Q_PROPERTY(int newProperty READ newProperty REVISION 1)
+ Q_PROPERTY(int newProperty READ newProperty REVISION(2, 1))
public:
Window();
@@ -66,7 +66,7 @@ public:
int newProperty();
public slots:
void normalMethod();
- Q_REVISION(1) void newMethod();
+ Q_REVISION(2, 1) void newMethod();
};
//! [Window class with revision]
diff --git a/src/corelib/doc/snippets/qstring/main.cpp b/src/corelib/doc/snippets/qstring/main.cpp
index 58d68d9375..271b6d7afc 100644
--- a/src/corelib/doc/snippets/qstring/main.cpp
+++ b/src/corelib/doc/snippets/qstring/main.cpp
@@ -433,14 +433,12 @@ void Widget::firstIndexOfFunction()
//! [93]
QString str = "the minimum";
str.indexOf(QRegularExpression("m[aeiou]"), 0); // returns 4
- //! [93]
- //! [99]
QString str = "the minimum";
QRegularExpressionMatch match;
str.indexOf(QRegularExpression("m[aeiou]"), 0, &match); // returns 4
// match.captured() == mi
- //! [99]
+ //! [93]
}
void Widget::insertFunction()
@@ -490,14 +488,12 @@ void Widget::lastIndexOfFunction()
//! [94]
QString str = "the minimum";
str.lastIndexOf(QRegularExpression("m[aeiou]")); // returns 8
- //! [94]
- //! [100]
QString str = "the minimum";
QRegularExpressionMatch match;
str.lastIndexOf(QRegularExpression("m[aeiou]"), -1, &match); // returns 8
// match.captured() == mu
- //! [100]
+ //! [94]
}
void Widget::leftFunction()