summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/doc/snippets/CMakeLists.txt2
-rw-r--r--src/corelib/doc/snippets/code/doc_src_containers.cpp554
-rw-r--r--src/corelib/doc/snippets/code/doc_src_groups.cpp33
-rw-r--r--src/corelib/doc/snippets/code/doc_src_objecttrees.cpp36
-rw-r--r--src/corelib/doc/snippets/code/doc_src_properties.cpp69
-rw-r--r--src/corelib/doc/snippets/code/doc_src_qalgorithms.cpp20
-rw-r--r--src/corelib/doc/snippets/code/doc_src_qcache.cpp40
-rw-r--r--src/corelib/doc/snippets/code/doc_src_qiterator.cpp557
-rw-r--r--src/corelib/doc/snippets/code/doc_src_qnamespace.cpp2
-rw-r--r--src/corelib/doc/snippets/code/doc_src_qplugin.cpp4
-rw-r--r--src/corelib/doc/snippets/code/doc_src_qset.cpp193
-rw-r--r--src/corelib/doc/snippets/code/doc_src_qvarlengtharray.cpp32
-rw-r--r--src/corelib/doc/snippets/code/doc_src_resources.cpp23
-rw-r--r--src/corelib/doc/snippets/eventfilters/CMakeLists.txt2
-rw-r--r--src/corelib/doc/snippets/qmetaobject-invokable/CMakeLists.txt2
-rw-r--r--src/corelib/doc/snippets/qmetaobject-revision/CMakeLists.txt2
-rw-r--r--src/corelib/doc/snippets/qprocess/CMakeLists.txt2
-rw-r--r--src/corelib/doc/src/objectmodel/objecttrees.qdoc8
-rw-r--r--src/corelib/tools/qarraydata.h10
-rw-r--r--src/corelib/tools/qarraydataops.h4
-rw-r--r--src/plugins/platforms/cocoa/qcocoaclipboard.mm1
-rw-r--r--src/plugins/platforms/cocoa/qcocoacursor.h3
-rw-r--r--src/plugins/platforms/cocoa/qcocoadrag.h12
-rw-r--r--src/plugins/platforms/cocoa/qcocoadrag.mm9
-rw-r--r--src/plugins/platforms/cocoa/qcocoahelpers.mm2
-rw-r--r--src/plugins/platforms/cocoa/qmacclipboard.h2
-rw-r--r--src/plugins/platforms/cocoa/qmacclipboard.mm1
-rw-r--r--src/plugins/platforms/cocoa/qmultitouch_mac_p.h9
-rw-r--r--src/plugins/platforms/cocoa/qnsview_dragging.mm2
29 files changed, 941 insertions, 695 deletions
diff --git a/src/corelib/doc/snippets/CMakeLists.txt b/src/corelib/doc/snippets/CMakeLists.txt
index 47ac9e860d6..78cd4f6b001 100644
--- a/src/corelib/doc/snippets/CMakeLists.txt
+++ b/src/corelib/doc/snippets/CMakeLists.txt
@@ -54,6 +54,8 @@ qt_internal_extend_target(corelib_snippets CONDITION QT_FEATURE_gui
qdebug/qdebugsnippet.cpp
)
+set_target_properties(corelib_snippets PROPERTIES COMPILE_OPTIONS "-w")
+
if ("${CMAKE_CXX_COMPILE_FEATURES}" MATCHES "cxx_std_23")
set_property(TARGET corelib_snippets PROPERTY CXX_STANDARD 23)
endif()
diff --git a/src/corelib/doc/snippets/code/doc_src_containers.cpp b/src/corelib/doc/snippets/code/doc_src_containers.cpp
index b5684624929..167437c0151 100644
--- a/src/corelib/doc/snippets/code/doc_src_containers.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_containers.cpp
@@ -3,6 +3,8 @@
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
+#include <QtCore>
+
//! [0]
class Employee
{
@@ -18,225 +20,225 @@ private:
};
//! [0]
-//! [range_for]
-QList<QString> list = {"A", "B", "C", "D"};
-for (const auto &item : list) {
- ...
-}
-//! [range_for]
-
-//! [range_for_as_const]
-QList<QString> list = {"A", "B", "C", "D"};
-for (const auto &item : std::as_const(list)) {
- ...
-}
-//! [range_for_as_const]
-
-//! [index]
-QList<QString> list = {"A", "B", "C", "D"};
-for (qsizetype i = 0; i < list.size(); ++i) {
- const auto &item = list.at(i);
- ...
-}
-//! [index]
-
-//! [1]
-QList<QString> list = {"A", "B", "C", "D"};
-
-QListIterator<QString> i(list);
-while (i.hasNext())
- QString s = i.next();
-//! [1]
-
-
-//! [2]
-QListIterator<QString> i(list);
-i.toBack();
-while (i.hasPrevious())
- QString s = i.previous();
-//! [2]
-
-
-//! [3]
-QMutableListIterator<int> i(list);
-while (i.hasNext()) {
- if (i.next() % 2 != 0)
- i.remove();
-}
-//! [3]
-
-
-//! [4]
-QMutableListIterator<int> i(list);
-i.toBack();
-while (i.hasPrevious()) {
- if (i.previous() % 2 != 0)
- i.remove();
-}
-//! [4]
-
-
-//! [5]
-QMutableListIterator<int> i(list);
-while (i.hasNext()) {
- if (i.next() > 128)
- i.setValue(128);
-}
-//! [5]
-
-
-//! [6]
-QMutableListIterator<int> i(list);
-while (i.hasNext())
- i.next() *= 2;
-//! [6]
-
-
-//! [7]
-QMap<QString, QString> map = {
- {"Paris", "France"},
- {"Guatemala City", "Guatemala"},
- {"Mexico City", "Mexico"},
- {"Moscow", "Russia"}
-};
-...
-
-QMutableMapIterator<QString, QString> i(map);
-while (i.hasNext()) {
- if (i.next().key().endsWith("City"))
- i.remove();
-}
-//! [7]
-
-
-//! [8]
-QMap<int, QWidget *> map;
-QHash<int, QWidget *> hash;
-
-QMapIterator<int, QWidget *> i(map);
-while (i.hasNext()) {
- i.next();
- hash.insert(i.key(), i.value());
-}
-//! [8]
-
-
-//! [9]
-QMutableMapIterator<int, QWidget *> i(map);
-while (i.findNext(widget))
- i.remove();
-//! [9]
+void examles()
+{
+ {
+ //! [range_for]
+ QList<QString> list = {"A", "B", "C", "D"};
+ for (const auto &item : list) {
+ //...
+ }
+ //! [range_for]
+ }
+ {
+ //! [range_for_as_const]
+ QList<QString> list = {"A", "B", "C", "D"};
+ for (const auto &item : std::as_const(list)) {
+ //...
+ }
+ //! [range_for_as_const]
+ }
-//! [10]
-QList<QString> list = {"A", "B", "C", "D"};
+ {
+ //! [index]
+ QList<QString> list = {"A", "B", "C", "D"};
+ for (qsizetype i = 0; i < list.size(); ++i) {
+ const auto &item = list.at(i);
+ //...
+ }
+ //! [index]
+ }
-for (auto i = list.begin(), end = list.end(); i != end; ++i)
- *i = (*i).toLower();
-//! [10]
+ {
+ //! [1]
+ QList<QString> list = {"A", "B", "C", "D"};
+ QListIterator<QString> i(list);
+ while (i.hasNext())
+ QString s = i.next();
+ //! [1]
+ }
-//! [11]
-QList<QString> list = {"A", "B", "C", "D"};
+ {
+ QList<QString> list = {"A", "B", "C", "D"};
-for (auto i = list.rbegin(), rend = list.rend(); i != rend; ++i)
- *i = i->toLower();
-//! [11]
+ //! [2]
+ QListIterator<QString> i(list);
+ i.toBack();
+ while (i.hasPrevious())
+ QString s = i.previous();
+ //! [2]
+ }
+ {
+ QList<int> list = {1, 2, 3, 4};
+ {
+ //! [3]
+ QMutableListIterator<int> i(list);
+ while (i.hasNext()) {
+ if (i.next() % 2 != 0)
+ i.remove();
+ }
+ //! [3]
+ }
+
+ {
+ //! [4]
+ QMutableListIterator<int> i(list);
+ i.toBack();
+ while (i.hasPrevious()) {
+ if (i.previous() % 2 != 0)
+ i.remove();
+ }
+ //! [4]
+ }
+
+ {
+ //! [5]
+ QMutableListIterator<int> i(list);
+ while (i.hasNext()) {
+ if (i.next() > 128)
+ i.setValue(128);
+ }
+ //! [5]
+ }
+
+ {
+ //! [6]
+ QMutableListIterator<int> i(list);
+ while (i.hasNext())
+ i.next() *= 2;
+ //! [6]
+ }
+ }
-//! [12]
-for (auto i = list.cbegin(), end = list.cend(); i != end; ++i)
- qDebug() << *i;
-//! [12]
+ {
+ //! [7]
+ QMap<QString, QString> map = {
+ {"Paris", "France"},
+ {"Guatemala City", "Guatemala"},
+ {"Mexico City", "Mexico"},
+ {"Moscow", "Russia"}
+ };
+ //...
+
+ QMutableMapIterator<QString, QString> i(map);
+ while (i.hasNext()) {
+ if (i.next().key().endsWith("City"))
+ i.remove();
+ }
+ //! [7]
+ }
+ {
+ //! [10]
+ QList<QString> list = {"A", "B", "C", "D"};
-//! [13]
-QMap<int, int> map;
-...
-for (auto i = map.cbegin(), end = map.cend(); i != end; ++i)
- qDebug() << i.key() << ':' << i.value();
-//! [13]
+ for (auto i = list.begin(), end = list.end(); i != end; ++i)
+ *i = (*i).toLower();
+ //! [10]
+ }
+ {
+ //! [11]
+ QList<QString> list = {"A", "B", "C", "D"};
-//! [14]
-// RIGHT
-const QList<int> sizes = splitter->sizes();
-for (auto i = sizes.begin(), end = sizes.end(); i != end; ++i)
- ...
+ for (auto i = list.rbegin(), rend = list.rend(); i != rend; ++i)
+ *i = i->toLower();
+ //! [11]
-// WRONG
-for (auto i = splitter->sizes().begin();
- i != splitter->sizes().end(); ++i)
- ...
-//! [14]
+ //! [12]
+ for (auto i = list.cbegin(), end = list.cend(); i != end; ++i)
+ qDebug() << *i;
+ //! [12]
-//! [15]
-QList<QString> values;
-...
-QString str;
-foreach (str, values)
- qDebug() << str;
-//! [15]
+ //! [13]
+ QMap<int, int> map;
+ //...
+ for (auto i = map.cbegin(), end = map.cend(); i != end; ++i)
+ qDebug() << i.key() << ':' << i.value();
+ //! [13]
+ }
-//! [16]
-QList<QString> values;
-...
-QListIterator<QString> i(values);
-while (i.hasNext()) {
- QString s = i.next();
- qDebug() << s;
-}
-//! [16]
+ {
+ //! [15]
+ QList<QString> values;
+ //...
+ QString str;
+ foreach (str, values)
+ qDebug() << str;
+ //! [15]
+ }
+ {
+ //! [16]
+ QList<QString> values;
+ //...
+ QListIterator<QString> i(values);
+ while (i.hasNext()) {
+ QString s = i.next();
+ qDebug() << s;
+ }
+ //! [16]
+ }
-//! [17]
-QList<QString> values;
-...
-foreach (const QString &str, values)
- qDebug() << str;
-//! [17]
+ {
+ //! [17]
+ QList<QString> values;
+ //...
+ foreach (const QString &str, values)
+ qDebug() << str;
+ //! [17]
+ }
+ {
+ //! [18]
+ QList<QString> values;
+ //...
+ foreach (const QString &str, values) {
+ if (str.isEmpty())
+ break;
+ qDebug() << str;
+ }
+ //! [18]
+ }
-//! [18]
-QList<QString> values;
-...
-foreach (const QString &str, values) {
- if (str.isEmpty())
- break;
- qDebug() << str;
-}
-//! [18]
+ {
+ //! [19]
+ QMap<QString, int> map;
+ //...
+ foreach (const QString &str, map.keys())
+ qDebug() << str << ':' << map.value(str);
+ //! [19]
+ }
+ {
+ //! [20]
+ QMultiMap<QString, int> map;
+ //...
+ foreach (const QString &str, map.uniqueKeys()) {
+ foreach (int i, map.values(str))
+ qDebug() << str << ':' << i;
+ }
+ //! [20]
+ }
-//! [19]
-QMap<QString, int> map;
-...
-foreach (const QString &str, map.keys())
- qDebug() << str << ':' << map.value(str);
-//! [19]
+ {
+ #if 0
+ //! [22]
+ CONFIG += no_keywords
+ //! [22]
-//! [20]
-QMultiMap<QString, int> map;
-...
-foreach (const QString &str, map.uniqueKeys()) {
- foreach (int i, map.values(str))
- qDebug() << str << ':' << i;
+ //! [cmake_no_keywords]
+ target_compile_definitions(my_app PRIVATE QT_NO_KEYWORDS)
+ //! [cmake_no_keywords]
+ #endif
+ }
}
-//! [20]
-
-
-//! [22]
-CONFIG += no_keywords
-//! [22]
-
-
-//! [cmake_no_keywords]
-target_compile_definitions(my_app PRIVATE QT_NO_KEYWORDS)
-//! [cmake_no_keywords]
-
//! [23]
QString onlyLetters(const QString &in)
@@ -250,61 +252,111 @@ QString onlyLetters(const QString &in)
}
//! [23]
-//! [24]
-QList<int> a, b;
-a.resize(100000); // make a big list filled with 0.
-
-QList<int>::iterator i = a.begin();
-// WRONG way of using the iterator i:
-b = a;
-/*
- Now we should be careful with iterator i since it will point to shared data
- If we do *i = 4 then we would change the shared instance (both vectors)
- The behavior differs from STL containers. Avoid doing such things in Qt.
-*/
-
-a[0] = 5;
-/*
- Container a is now detached from the shared data,
- and even though i was an iterator from the container a, it now works as an iterator in b.
- Here the situation is that (*i) == 0.
-*/
-
-b.clear(); // Now the iterator i is completely invalid.
-
-int j = *i; // Undefined behavior!
-/*
- The data from b (which i pointed to) is gone.
- This would be well-defined with STL containers (and (*i) == 5),
- but with QList this is likely to crash.
-*/
-//! [24]
-
-//! [25]
-QList<int> list = {1, 2, 3, 4, 4, 5};
-QSet<int> set(list.cbegin(), list.cend());
-/*
- Will generate a QSet containing 1, 2, 3, 4, 5.
-*/
-//! [25]
-
-//! [26]
-QList<int> list = {2, 3, 1};
-
-std::sort(list.begin(), list.end());
-/*
- Sort the list, now contains { 1, 2, 3 }
-*/
-
-std::reverse(list.begin(), list.end());
-/*
- Reverse the list, now contains { 3, 2, 1 }
-*/
-
-int even_elements =
- std::count_if(list.begin(), list.end(), [](int element) { return (element % 2 == 0); });
-/*
- Count how many elements that are even numbers, 1
-*/
-
-//! [26]
+void wrap()
+{
+ //! [24]
+ QList<int> a, b;
+ a.resize(100000); // make a big list filled with 0.
+
+ QList<int>::iterator i = a.begin();
+ // WRONG way of using the iterator i:
+ b = a;
+ /*
+ Now we should be careful with iterator i since it will point to shared data
+ If we do *i = 4 then we would change the shared instance (both vectors)
+ The behavior differs from STL containers. Avoid doing such things in Qt.
+ */
+
+ a[0] = 5;
+ /*
+ Container a is now detached from the shared data,
+ and even though i was an iterator from the container a, it now works as an iterator in b.
+ Here the situation is that (*i) == 0.
+ */
+
+ b.clear(); // Now the iterator i is completely invalid.
+
+ int j = *i; // Undefined behavior!
+ /*
+ The data from b (which i pointed to) is gone.
+ This would be well-defined with STL containers (and (*i) == 5),
+ but with QList this is likely to crash.
+ */
+ //! [24]
+
+ {
+ //! [25]
+ QList<int> list = {1, 2, 3, 4, 4, 5};
+ QSet<int> set(list.cbegin(), list.cend());
+ /*
+ Will generate a QSet containing 1, 2, 3, 4, 5.
+ */
+ //! [25]
+ }
+
+ //! [26]
+ QList<int> list = {2, 3, 1};
+
+ std::sort(list.begin(), list.end());
+ /*
+ Sort the list, now contains { 1, 2, 3 }
+ */
+
+ std::reverse(list.begin(), list.end());
+ /*
+ Reverse the list, now contains { 3, 2, 1 }
+ */
+
+ int even_elements =
+ std::count_if(list.begin(), list.end(), [](int element) { return (element % 2 == 0); });
+ /*
+ Count how many elements that are even numbers, 1
+ */
+ //! [26]
+}
+
+#if __has_include(<QWidget>)
+
+#include <QWidget>
+#include <QSplitter>
+
+void examples_with_widgets()
+{
+ {
+ //! [8]
+ QMap<int, QWidget *> map;
+ QHash<int, QWidget *> hash;
+
+ QMapIterator<int, QWidget *> i(map);
+ while (i.hasNext()) {
+ i.next();
+ hash.insert(i.key(), i.value());
+ }
+ //! [8]
+ }
+
+ {
+ QMap<int, QWidget *> map;
+ QWidget* widget;
+ //! [9]
+ QMutableMapIterator<int, QWidget *> i(map);
+ while (i.findNext(widget))
+ i.remove();
+ //! [9]
+ }
+
+ QSplitter* splitter;
+
+ //! [14]
+ // RIGHT
+ const QList<int> sizes = splitter->sizes();
+ for (auto i = sizes.begin(), end = sizes.end(); i != end; ++i)
+ {/*...*/}
+
+ // WRONG
+ for (auto i = splitter->sizes().begin();
+ i != splitter->sizes().end(); ++i)
+ {/*...*/}
+ //! [14]
+}
+#endif
diff --git a/src/corelib/doc/snippets/code/doc_src_groups.cpp b/src/corelib/doc/snippets/code/doc_src_groups.cpp
index a0901904db0..2d7c2f96056 100644
--- a/src/corelib/doc/snippets/code/doc_src_groups.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_groups.cpp
@@ -1,6 +1,15 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QPen>
+#include <QPainter>
+
+class QPenPrivate {
+public:
+ int ref = 1;
+ Qt::PenStyle style;
+};
+
//! [0]
void QPen::setStyle(Qt::PenStyle style)
{
@@ -11,19 +20,21 @@ void QPen::setStyle(Qt::PenStyle style)
void QPen::detach()
{
if (d->ref != 1) {
- ... // perform a deep copy
+ //... // perform a deep copy
}
}
//! [0]
+void example()
+{
+ //! [1]
+ QPixmap p1, p2;
+ p1.load("image.bmp");
+ p2 = p1; // p1 and p2 share data
-//! [1]
-QPixmap p1, p2;
-p1.load("image.bmp");
-p2 = p1; // p1 and p2 share data
-
-QPainter paint;
-paint.begin(&p2); // cuts p2 loose from p1
-paint.drawText(0,50, "Hi");
-paint.end();
-//! [1]
+ QPainter paint;
+ paint.begin(&p2); // cuts p2 loose from p1
+ paint.drawText(0,50, "Hi");
+ paint.end();
+ //! [1]
+}
diff --git a/src/corelib/doc/snippets/code/doc_src_objecttrees.cpp b/src/corelib/doc/snippets/code/doc_src_objecttrees.cpp
index b7c71ccb6b0..8b55ad9b157 100644
--- a/src/corelib/doc/snippets/code/doc_src_objecttrees.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_objecttrees.cpp
@@ -1,23 +1,31 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//![0]
+#include <QPushButton>
+
+//![open]
int main()
{
- QWidget window;
- QPushButton quit("Quit", &window);
- ...
-}
-//![0]
+//![open]
+ {
+ //![example1]
+ QWidget window;
+ QPushButton quit("Quit", &window);
+ //...
+ //![example1]
+ }
-//![1]
-int main()
-{
- QPushButton quit("Quit");
- QWidget window;
+ {
+ //![example2]
+ QPushButton quit("Quit");
+ QWidget window;
+
+ quit.setParent(&window);
+ //...
+ //![example2]
+ }
- quit.setParent(&window);
- ...
+//![close]
}
-//![1]
+//![close]
diff --git a/src/corelib/doc/snippets/code/doc_src_properties.cpp b/src/corelib/doc/snippets/code/doc_src_properties.cpp
index 190a8437101..eafa7acda3b 100644
--- a/src/corelib/doc/snippets/code/doc_src_properties.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_properties.cpp
@@ -1,6 +1,7 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#ifdef QPROPERTY_MACRO
//! [0]
Q_PROPERTY(type name
(READ getFunction [WRITE setFunction] |
@@ -25,33 +26,40 @@ Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
Q_PROPERTY(QCursor cursor READ cursor WRITE setCursor RESET unsetCursor)
//! [1]
-
//! [2]
Q_PROPERTY(QDate date READ getDate WRITE setDate)
//! [2]
+#endif
+#if __has_include(<QPushButton>)
+#include <QPushButton>
+void button_example()
+{
+ //! [3]
+ QPushButton *button = new QPushButton;
+ QObject *object = button;
-//! [3]
-QPushButton *button = new QPushButton;
-QObject *object = button;
-
-button->setDown(true);
-object->setProperty("down", true);
-//! [3]
-
-
-//! [4]
-QObject *object = ...
-const QMetaObject *metaobject = object->metaObject();
-int count = metaobject->propertyCount();
-for (int i=0; i<count; ++i) {
- QMetaProperty metaproperty = metaobject->property(i);
- const char *name = metaproperty.name();
- QVariant value = object->property(name);
- ...
+ button->setDown(true);
+ object->setProperty("down", true);
+ //! [3]
}
-//! [4]
+#endif
+#include <QMetaProperty>
+void qobject_example()
+{
+ //! [4]
+ QObject *object = new QObject;
+ const QMetaObject *metaobject = object->metaObject();
+ int count = metaobject->propertyCount();
+ for (int i=0; i<count; ++i) {
+ QMetaProperty metaproperty = metaobject->property(i);
+ const char *name = metaproperty.name();
+ QVariant value = object->property(name);
+ //...
+ }
+ //! [4]
+}
//! [5]
class MyClass : public QObject
@@ -85,16 +93,17 @@ private:
};
//! [5]
+void example(){
+ //! [6]
+ MyClass *myinstance = new MyClass;
+ QObject *object = myinstance;
-//! [6]
-MyClass *myinstance = new MyClass;
-QObject *object = myinstance;
-
-myinstance->setPriority(MyClass::VeryHigh);
-object->setProperty("priority", "VeryHigh");
-//! [6]
-
+ myinstance->setPriority(MyClass::VeryHigh);
+ object->setProperty("priority", "VeryHigh");
+ //! [6]
+}
+#ifdef QPROPERTY_MACRO
//! [7]
Q_CLASSINFO("DefaultProperty", "content")
//! [7]
@@ -103,7 +112,7 @@ Q_CLASSINFO("DefaultProperty", "content")
Q_PROPERTY(QColor color MEMBER m_color NOTIFY colorChanged)
Q_PROPERTY(qreal spacing MEMBER m_spacing NOTIFY spacingChanged)
Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)
- ...
+ //...
signals:
void colorChanged();
void spacingChanged();
@@ -114,4 +123,4 @@ private:
qreal m_spacing;
QString m_text;
//! [8]
-
+#endif
diff --git a/src/corelib/doc/snippets/code/doc_src_qalgorithms.cpp b/src/corelib/doc/snippets/code/doc_src_qalgorithms.cpp
index f2b94a74165..9155345508a 100644
--- a/src/corelib/doc/snippets/code/doc_src_qalgorithms.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_qalgorithms.cpp
@@ -1,11 +1,17 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [1]
-QList<Employee *> list;
-list.append(new Employee("Blackpool", "Stephen"));
-list.append(new Employee("Twist", "Oliver"));
+#include <QList>
+#include <QColor>
-qDeleteAll(list.begin(), list.end());
-list.clear();
-//! [1]
+void example()
+{
+ //! [1]
+ QList<QColor *> list;
+ list.append(new QColor(Qt::blue));
+ list.append(new QColor(Qt::yellow));
+
+ qDeleteAll(list.begin(), list.end());
+ list.clear();
+ //! [1]
+}
diff --git a/src/corelib/doc/snippets/code/doc_src_qcache.cpp b/src/corelib/doc/snippets/code/doc_src_qcache.cpp
index a15a8027600..3157981f3fa 100644
--- a/src/corelib/doc/snippets/code/doc_src_qcache.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_qcache.cpp
@@ -1,20 +1,34 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [0]
-QCache<int, Employee> cache;
-//! [0]
+#include <QCache>
+struct Employee {
+ void setId(int id);
+ int id() const { return 0; }
+ void setName(const QString &name);
+};
-//! [1]
-Employee *employee = new Employee;
-employee->setId(37);
-employee->setName("Richard Schmit");
-...
-cache.insert(employee->id(), employee);
-//! [1]
+struct MyDataStructure { };
+void example()
+{
+ //! [0]
+ QCache<int, Employee> cache;
+ //! [0]
-//! [2]
-QCache<int, MyDataStructure> cache(5000);
-//! [2]
+
+ //! [1]
+ Employee *employee = new Employee;
+ employee->setId(37);
+ employee->setName("Richard Schmit");
+ //...
+ cache.insert(employee->id(), employee);
+ //! [1]
+
+ {
+ //! [2]
+ QCache<int, MyDataStructure> cache(5000);
+ //! [2]
+ }
+}
diff --git a/src/corelib/doc/snippets/code/doc_src_qiterator.cpp b/src/corelib/doc/snippets/code/doc_src_qiterator.cpp
index 0d921b87e67..209e98af522 100644
--- a/src/corelib/doc/snippets/code/doc_src_qiterator.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_qiterator.cpp
@@ -1,278 +1,349 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-//! [0]
-QList<float> list;
-...
-QListIterator<float> i(list);
-while (i.hasNext())
- float f = i.next();
-//! [0]
-
-
-//! [1]
-QListIterator<float> i(list);
-i.toBack();
-while (i.hasPrevious())
- float f = i.previous();
-//! [1]
-
-//! [6]
-QSet<QString> set;
-...
-QSetIterator<QString> i(set);
-while (i.hasNext())
- float f = i.next();
-//! [6]
-
-//! [8]
-QList<float> list;
-...
-QMutableListIterator<float> i(list);
-while (i.hasNext())
- float f = i.next();
-//! [8]
-
-
-//! [9]
-QMutableListIterator<float> i(list);
-i.toBack();
-while (i.hasPrevious())
- float f = i.previous();
-//! [9]
-
-
-//! [10]
-QMutableListIterator<int> i(list);
-while (i.hasNext()) {
- int val = i.next();
- if (val < 0) {
- i.setValue(-val);
- } else if (val == 0) {
- i.remove();
+#include <QList>
+#include <QSet>
+
+void example()
+{
+ {
+ //! [0]
+ QList<float> list;
+ //...
+ QListIterator<float> i(list);
+ while (i.hasNext())
+ float f = i.next();
+ //! [0]
}
-}
-//! [10]
-
-//! [17]
-QSet<float> set;
-...
-QMutableSetIterator<float> i(set);
-while (i.hasNext())
- float f = i.next();
-//! [17]
-//! [19]
-QMutableListIterator<int> i(list);
-while (i.hasNext()) {
- int val = i.next();
- if (val < -32768 || val > 32767)
- i.remove();
-}
-//! [19]
-
-//! [22]
-QMutableSetIterator<int> i(set);
-while (i.hasNext()) {
- int val = i.next();
- if (val < -32768 || val > 32767)
- i.remove();
-}
-//! [22]
-
-
-//! [23]
-QMutableListIterator<double> i(list);
-while (i.hasNext()) {
- double val = i.next();
- i.setValue(std::sqrt(val));
-}
-//! [23]
-
-//! [26]
-QMap<int, QWidget *> map;
-...
-QMapIterator<int, QWidget *> i(map);
-while (i.hasNext()) {
- i.next();
- qDebug() << i.key() << ": " << i.value();
-}
-//! [26]
-
-
-//! [27]
-QMapIterator<int, QWidget *> i(map);
-i.toBack();
-while (i.hasPrevious()) {
- i.previous();
- qDebug() << i.key() << ": " << i.value();
-}
-//! [27]
-
-
-//! [28]
-QMapIterator<int, QWidget *> i(map);
-while (i.findNext(widget)) {
- qDebug() << "Found widget " << widget << " under key "
- << i.key();
-}
-//! [28]
-
-//! [26multi]
-QMultiMap<int, QWidget *> multimap;
-...
-QMultiMapIterator<int, QWidget *> i(multimap);
-while (i.hasNext()) {
- i.next();
- qDebug() << i.key() << ": " << i.value();
-}
-//! [26multi]
+ QList<float> list;
+ {
+ //! [1]
+ QListIterator<float> i(list);
+ i.toBack();
+ while (i.hasPrevious())
+ float f = i.previous();
+ //! [1]
+ }
-//! [27multi]
-QMultiMapIterator<int, QWidget *> i(multimap);
-i.toBack();
-while (i.hasPrevious()) {
- i.previous();
- qDebug() << i.key() << ": " << i.value();
-}
-//! [27multi]
+ {
+ //! [6]
+ QSet<QString> set;
+ //...
+ QSetIterator<QString> i(set);
+ while (i.hasNext())
+ QString f = i.next();
+ //! [6]
+ }
+ {
+ //! [8]
+ QList<float> list;
+ //...
+ QMutableListIterator<float> i(list);
+ while (i.hasNext())
+ float f = i.next();
+ //! [8]
+ }
-//! [28multi]
-QMultiMapIterator<int, QWidget *> i(multimap);
-while (i.findNext(widget)) {
- qDebug() << "Found widget " << widget << " under key "
- << i.key();
-}
-//! [28multi]
+ {
+ //! [9]
+ QMutableListIterator<float> i(list);
+ i.toBack();
+ while (i.hasPrevious())
+ float f = i.previous();
+ //! [9]
+ }
+ {
+ QList<int> list = {1, 2, 3, 4, 5};
+ //! [10]
+ QMutableListIterator<int> i(list);
+ while (i.hasNext()) {
+ int val = i.next();
+ if (val < 0) {
+ i.setValue(-val);
+ } else if (val == 0) {
+ i.remove();
+ }
+ }
+ //! [10]
+ }
-//! [29]
-QHash<int, QWidget *> hash;
-...
-QHashIterator<int, QWidget *> i(hash);
-while (i.hasNext()) {
- i.next();
- qDebug() << i.key() << ": " << i.value();
-}
-//! [29]
+ {
+ //! [17]
+ QSet<float> set;
+ //...
+ QMutableSetIterator<float> i(set);
+ while (i.hasNext())
+ float f = i.next();
+ //! [17]
+ }
+ {
+ QList<int> list = {1, 2, 3, 4, 5};
+ //! [19]
+ QMutableListIterator<int> i(list);
+ while (i.hasNext()) {
+ int val = i.next();
+ if (val < -32768 || val > 32767)
+ i.remove();
+ }
+ //! [19]
+ }
-//! [31]
-QHashIterator<int, QWidget *> i(hash);
-while (i.findNext(widget)) {
- qDebug() << "Found widget " << widget << " under key "
- << i.key();
-}
-//! [31]
+ {
+ QSet<int> set;
+ //! [22]
+ QMutableSetIterator<int> i(set);
+ while (i.hasNext()) {
+ int val = i.next();
+ if (val < -32768 || val > 32767)
+ i.remove();
+ }
+ //! [22]
+ }
+ {
+ QList<double> list;
+ //! [23]
+ QMutableListIterator<double> i(list);
+ while (i.hasNext()) {
+ double val = i.next();
+ i.setValue(std::sqrt(val));
+ }
+ //! [23]
+ }
-//! [32]
-QMap<int, QWidget *> map;
-...
-QMutableMapIterator<int, QWidget *> i(map);
-while (i.hasNext()) {
- i.next();
- qDebug() << i.key() << ": " << i.value();
+ {
+ //! [25]
+ QList<int> list;
+ //...
+ QListIterator<int> i(list);
+ while (i.hasNext())
+ int val = i.next();
+ //! [25]
+ }
}
-//! [32]
-
-//! [33]
-QMutableMapIterator<int, QWidget *> i(map);
-i.toBack();
-while (i.hasPrevious()) {
- i.previous();
- qDebug() << i.key() << ": " << i.value();
-}
-//! [33]
+#if __has_include(<QWidget>)
+#include <QWidget>
+void example_widgets()
+{
+ QMap<int, QWidget *> map;
+ {
+ //! [26]
+ QMap<int, QWidget *> map;
+ //...
+ QMapIterator<int, QWidget *> i(map);
+ while (i.hasNext()) {
+ i.next();
+ qDebug() << i.key() << ": " << i.value();
+ }
+ //! [26]
+ }
+ {
+ //! [27]
+ QMapIterator<int, QWidget *> i(map);
+ i.toBack();
+ while (i.hasPrevious()) {
+ i.previous();
+ qDebug() << i.key() << ": " << i.value();
+ }
+ //! [27]
+ }
-//! [34]
-QMutableMapIterator<int, QWidget *> i(map);
-while (i.findNext(widget)) {
- qDebug() << "Found widget " << widget << " under key "
- << i.key();
-}
-//! [34]
+ QWidget *widget;
+ {
+ //! [28]
+ QMapIterator<int, QWidget *> i(map);
+ while (i.findNext(widget)) {
+ qDebug() << "Found widget " << widget << " under key "
+ << i.key();
+ }
+ //! [28]
+ }
+ {
+ //! [26multi]
+ QMultiMap<int, QWidget *> multimap;
+ //...
+ QMultiMapIterator<int, QWidget *> i(multimap);
+ while (i.hasNext()) {
+ i.next();
+ qDebug() << i.key() << ": " << i.value();
+ }
+ //! [26multi]
+ }
-//! [35]
-QMutableMapIterator<QString, QString> i(map);
-while (i.hasNext()) {
- i.next();
- if (i.key() == i.value())
- i.remove();
-}
-//! [35]
+ QMultiMap<int, QWidget *> multimap;
+ {
+ //! [27multi]
+ QMultiMapIterator<int, QWidget *> i(multimap);
+ i.toBack();
+ while (i.hasPrevious()) {
+ i.previous();
+ qDebug() << i.key() << ": " << i.value();
+ }
+ //! [27multi]
+ }
+ {
+ //! [28multi]
+ QMultiMapIterator<int, QWidget *> i(multimap);
+ while (i.findNext(widget)) {
+ qDebug() << "Found widget " << widget << " under key "
+ << i.key();
+ }
+ //! [28multi]
+ }
-//! [32multi]
-QMultiMap<int, QWidget *> multimap;
-...
-QMutableMultiMapIterator<int, QWidget *> i(multimap);
-while (i.hasNext()) {
- i.next();
- qDebug() << i.key() << ": " << i.value();
-}
-//! [32multi]
+ {
+ //! [29]
+ QHash<int, QWidget *> hash;
+ //...
+ QHashIterator<int, QWidget *> i(hash);
+ while (i.hasNext()) {
+ i.next();
+ qDebug() << i.key() << ": " << i.value();
+ }
+ //! [29]
+ }
+ QHash<int, QWidget *> hash;
+ {
+ //! [31]
+ QHashIterator<int, QWidget *> i(hash);
+ while (i.findNext(widget)) {
+ qDebug() << "Found widget " << widget << " under key "
+ << i.key();
+ }
+ //! [31]
+ }
-//! [33multi]
-QMutableMultiMapIterator<int, QWidget *> i(multimap);
-i.toBack();
-while (i.hasPrevious()) {
- i.previous();
- qDebug() << i.key() << ": " << i.value();
-}
-//! [33multi]
+ {
+ //! [32]
+ QMap<int, QWidget *> map;
+ //...
+ QMutableMapIterator<int, QWidget *> i(map);
+ while (i.hasNext()) {
+ i.next();
+ qDebug() << i.key() << ": " << i.value();
+ }
+ //! [32]
+ }
+ {
+ //! [33]
+ QMutableMapIterator<int, QWidget *> i(map);
+ i.toBack();
+ while (i.hasPrevious()) {
+ i.previous();
+ qDebug() << i.key() << ": " << i.value();
+ }
+ //! [33]
+ }
-//! [34multi]
-QMutableMultiMapIterator<int, QWidget *> i(multimap);
-while (i.findNext(widget)) {
- qDebug() << "Found widget " << widget << " under key "
- << i.key();
-}
-//! [34multi]
+ {
+ //! [34]
+ QMutableMapIterator<int, QWidget *> i(map);
+ while (i.findNext(widget)) {
+ qDebug() << "Found widget " << widget << " under key "
+ << i.key();
+ }
+ //! [34]
+ }
+ {
+ QMap<QString, QString> map;
+ //! [35]
+ QMutableMapIterator<QString, QString> i(map);
+ while (i.hasNext()) {
+ i.next();
+ if (i.key() == i.value())
+ i.remove();
+ }
+ //! [35]
+ }
-//! [35multi]
-QMutableMultiMapIterator<QString, QString> i(multimap);
-while (i.hasNext()) {
- i.next();
- if (i.key() == i.value())
- i.remove();
-}
-//! [35multi]
+ {
+ //! [32multi]
+ QMultiMap<int, QWidget *> multimap;
+ //...
+ QMutableMultiMapIterator<int, QWidget *> i(multimap);
+ while (i.hasNext()) {
+ i.next();
+ qDebug() << i.key() << ": " << i.value();
+ }
+ //! [32multi]
+ }
+ {
+ //! [33multi]
+ QMutableMultiMapIterator<int, QWidget *> i(multimap);
+ i.toBack();
+ while (i.hasPrevious()) {
+ i.previous();
+ qDebug() << i.key() << ": " << i.value();
+ }
+ //! [33multi]
+ }
-//! [36]
-QHash<int, QWidget *> hash;
-...
-QMutableHashIterator<QString, QWidget *> i(hash);
-while (i.hasNext()) {
- i.next();
- qDebug() << i.key() << ": " << i.value();
-}
-//! [36]
+ {
+ //! [34multi]
+ QMutableMultiMapIterator<int, QWidget *> i(multimap);
+ while (i.findNext(widget)) {
+ qDebug() << "Found widget " << widget << " under key "
+ << i.key();
+ }
+ //! [34multi]
+ }
+ {
+ QMultiMap<QString, QString> multimap;
+ //! [35multi]
+ QMutableMultiMapIterator<QString, QString> i(multimap);
+ while (i.hasNext()) {
+ i.next();
+ if (i.key() == i.value())
+ i.remove();
+ }
+ //! [35multi]
+ }
-//! [38]
-QMutableHashIterator<int, QWidget *> i(hash);
-while (i.findNext(widget)) {
- qDebug() << "Found widget " << widget << " under key "
- << i.key();
-}
-//! [38]
+ {
+ //! [36]
+ QHash<int, QWidget *> hash;
+ //...
+ QMutableHashIterator<int, QWidget *> i(hash);
+ while (i.hasNext()) {
+ i.next();
+ qDebug() << i.key() << ": " << i.value();
+ }
+ //! [36]
+ }
+ {
+ //! [38]
+ QMutableHashIterator<int, QWidget *> i(hash);
+ while (i.findNext(widget)) {
+ qDebug() << "Found widget " << widget << " under key "
+ << i.key();
+ }
+ //! [38]
+ }
-//! [39]
-QMutableHashIterator<QString, QString> i(hash);
-while (i.hasNext()) {
- i.next();
- if (i.key() == i.value())
- i.remove();
+ {
+ QHash<QString, QString> hash;
+ //! [39]
+ QMutableHashIterator<QString, QString> i(hash);
+ while (i.hasNext()) {
+ i.next();
+ if (i.key() == i.value())
+ i.remove();
+ }
+ //! [39]
+ }
}
-//! [39]
+#endif
diff --git a/src/corelib/doc/snippets/code/doc_src_qnamespace.cpp b/src/corelib/doc/snippets/code/doc_src_qnamespace.cpp
index 10845855840..d753874f0dd 100644
--- a/src/corelib/doc/snippets/code/doc_src_qnamespace.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_qnamespace.cpp
@@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QEvent>
+
//! [1]
enum CustomEventPriority
{
diff --git a/src/corelib/doc/snippets/code/doc_src_qplugin.cpp b/src/corelib/doc/snippets/code/doc_src_qplugin.cpp
index 3bca27b9661..4382d13838a 100644
--- a/src/corelib/doc/snippets/code/doc_src_qplugin.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_qplugin.cpp
@@ -1,10 +1,12 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QtPlugin>
+
//! [0]
namespace Foo
{
- struct MyInterface { ... };
+ struct MyInterface { /*...*/ };
}
Q_DECLARE_INTERFACE(Foo::MyInterface, "org.examples.MyInterface")
diff --git a/src/corelib/doc/snippets/code/doc_src_qset.cpp b/src/corelib/doc/snippets/code/doc_src_qset.cpp
index 98a6f336f5a..8342e1d6f98 100644
--- a/src/corelib/doc/snippets/code/doc_src_qset.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_qset.cpp
@@ -1,107 +1,134 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [0]
-QSet<QString> set;
-//! [0]
+#include <QtCore>
+#include <iostream>
+using namespace std;
+void snippets_0_3()
+{
+ //! [0]
+ QSet<QString> set;
+ //! [0]
-//! [1]
-set.insert("one");
-set.insert("three");
-set.insert("seven");
-//! [1]
+ //! [1]
+ set.insert("one");
+ set.insert("three");
+ set.insert("seven");
+ //! [1]
-//! [2]
-set << "twelve" << "fifteen" << "nineteen";
-//! [2]
+ //! [2]
+ set << "twelve" << "fifteen" << "nineteen";
+ //! [2]
-//! [3]
-if (!set.contains("ninety-nine"))
- ...
-//! [3]
-
-//! [4]
-QSetIterator<QWidget *> i(set);
-while (i.hasNext()) {
- QWidget *w = i.next();
- qDebug() << w;
+ //! [3]
+ if (!set.contains("ninety-nine"))
+ {/*...*/}
+ //! [3]
}
-//! [4]
-
-//! [5]
-for (auto i = set.cbegin(), end = set.cend(); i != end; ++i)
- qDebug() << *i;
-//! [5]
+#if __has_include(<QWidget>)
+#include <QWidget>
-//! [6]
-QSet<QString> set;
-...
-for (const auto &value : set)
- qDebug() << value;
-//! [6]
+void example_widgets()
+{
+ QSet<QWidget *> set;
+ //! [4]
+ QSetIterator<QWidget *> i(set);
+ while (i.hasNext()) {
+ QWidget *w = i.next();
+ qDebug() << w;
+ }
+ //! [4]
+}
+#endif
+
+void snippets_5_12()
+{
+ QSet<QString> set;
+
+ //! [5]
+ for (auto i = set.cbegin(), end = set.cend(); i != end; ++i)
+ qDebug() << *i;
+ //! [5]
+
+ {
+ //! [6]
+ QSet<QString> set;
+ //...
+ for (const auto &value : set)
+ qDebug() << value;
+ //! [6]
+ }
+ {
+ QString values[3];
+ //! [7]
+ QSet<QString> set;
+ set.reserve(20000);
+ for (int i = 0; i < 20000; ++i)
+ set.insert(values[i]);
+ //! [7]
+ }
-//! [7]
-QSet<QString> set;
-set.reserve(20000);
-for (int i = 0; i < 20000; ++i)
- set.insert(values[i]);
-//! [7]
+ {
+ //! [8]
+ QSet<QString> set = {"January", "February", /*...*/ "December"};
+ // i is a QSet<QString>::iterator
+ for (auto i = set.begin(), end = set.end(); i != end; ++i)
+ qDebug() << *i;
+ //! [8]
+ }
-//! [8]
-QSet<QString> set = {"January", "February", ... "December"}
+ {
+ //! [9]
+ QSet<QString> set = {"January", "February", /*...*/ "December"};
+
+ auto i = set.begin();
+ while (i != set.end()) {
+ if ((*i).startsWith('J')) {
+ i = set.erase(i);
+ } else {
+ ++i;
+ }
+ }
+ //! [9]
+ }
-// i is a QSet<QString>::iterator
-for (auto i = set.begin(), end = set.end(); i != end; ++i)
- qDebug() << *i;
-//! [8]
+ {
+ //! [10]
+ QSet<QString> set;
+ //...
+ const auto predicate = [](const QString &s) { return s.compare("Jeanette", Qt::CaseInsensitive) == 0; };
+ QSet<QString>::iterator it = std::find_if(set.begin(), set.end(), predicate);
+ if (it != set.end())
+ cout << "Found Jeanette" << endl;
+ //! [10]
+ }
+ {
+ //! [11]
+ QSet<QString> set = {"January", "February", /*...*/ "December"};
-//! [9]
-QSet<QString> set = {"January", "February", ... "December"};
+ // i is QSet<QString>::const_iterator
+ for (auto i = set.cbegin(), end = set.cend(); i != end; ++i)
+ qDebug() << *i;
+ //! [11]
+ }
-auto i = set.begin();
-while (i != set.end()) {
- if ((*i).startsWith('J')) {
- i = set.erase(i);
- } else {
- ++i;
+ {
+ //! [12]
+ QSet<QString> set;
+ //...
+ const auto predicate = [](const QString &s) { return s.compare("Jeanette", Qt::CaseInsensitive) == 0; };
+ QSet<QString>::const_iterator it = std::find_if(set.cbegin(), set.cend(), predicate);
+ if (it != set.constEnd())
+ cout << "Found Jeanette" << endl;
+ //! [12]
}
}
-//! [9]
-
-
-//! [10]
-QSet<QString> set;
-...
-const auto predicate = [](const QString &s) { return s.compare("Jeanette", Qt::CaseInsensitive) == 0; };
-QSet<QString>::iterator it = std::find_if(set.begin(), set.end(), predicate);
-if (it != set.end())
- cout << "Found Jeanette" << endl;
-//! [10]
-
-
-//! [11]
-QSet<QString> set = {"January", "February", ... "December"};
-
-// i is QSet<QString>::const_iterator
-for (auto i = set.cbegin(), end = set.cend(); i != end; ++i)
- qDebug() << *i;
-//! [11]
-
-
-//! [12]
-QSet<QString> set;
-...
-const auto predicate = [](const QString &s) { return s.compare("Jeanette", Qt::CaseInsensitive) == 0; };
-QSet<QString>::const_iterator it = std::find_if(set.cbegin(), set.cend(), predicate);
-if (it != set.constEnd())
- cout << "Found Jeanette" << endl;
-//! [12]
diff --git a/src/corelib/doc/snippets/code/doc_src_qvarlengtharray.cpp b/src/corelib/doc/snippets/code/doc_src_qvarlengtharray.cpp
index 080874fc77d..4d2ccc82c2e 100644
--- a/src/corelib/doc/snippets/code/doc_src_qvarlengtharray.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_qvarlengtharray.cpp
@@ -1,21 +1,24 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QVarLengthArray>
+
+#if 0
//! [0]
-int myfunc(int n)
+int myfunc_wrong(int n)
{
int table[n + 1]; // WRONG
- ...
+ //...
return table[n];
}
//! [0]
-
+#endif
//! [1]
-int myfunc(int n)
+int myfunc_correct(int n)
{
int *table = new int[n + 1];
- ...
+ //...
int ret = table[n];
delete[] table;
return ret;
@@ -24,18 +27,21 @@ int myfunc(int n)
//! [2]
-int myfunc(int n)
+int myfunc_q(int n)
{
QVarLengthArray<int, 1024> array(n + 1);
- ...
+ //...
return array[n];
}
//! [2]
-//! [3]
-QVarLengthArray<int> array(10);
-int *data = array.data();
-for (int i = 0; i < 10; ++i)
- data[i] = 2 * i;
-//! [3]
+void example()
+{
+ //! [3]
+ QVarLengthArray<int> array(10);
+ int *data = array.data();
+ for (int i = 0; i < 10; ++i)
+ data[i] = 2 * i;
+ //! [3]
+}
diff --git a/src/corelib/doc/snippets/code/doc_src_resources.cpp b/src/corelib/doc/snippets/code/doc_src_resources.cpp
index 04ecf810ec1..9a244b9239d 100644
--- a/src/corelib/doc/snippets/code/doc_src_resources.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_resources.cpp
@@ -1,10 +1,25 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [4]
-QResource::registerResource("/path/to/myresource.rcc");
-//! [4]
+#include <QResource>
+#include <QFile>
+void wrap()
+{
+ //! [4]
+ QResource::registerResource("/path/to/myresource.rcc");
+ //! [4]
+}
+
+class BaseClass {
+ public:
+ BaseClass() {}
+};
+
+class MyClass : BaseClass {
+ public:
+ MyClass();
+};
//! [5]
MyClass::MyClass() : BaseClass()
@@ -12,6 +27,6 @@ MyClass::MyClass() : BaseClass()
Q_INIT_RESOURCE(resources);
QFile file(":/myfile.dat");
- ...
+ //...
}
//! [5]
diff --git a/src/corelib/doc/snippets/eventfilters/CMakeLists.txt b/src/corelib/doc/snippets/eventfilters/CMakeLists.txt
index 57371419e50..7da83cbdf6e 100644
--- a/src/corelib/doc/snippets/eventfilters/CMakeLists.txt
+++ b/src/corelib/doc/snippets/eventfilters/CMakeLists.txt
@@ -1,5 +1,7 @@
add_library(corelib_snippets_eventfilters OBJECT)
+set_target_properties(corelib_snippets_eventfilters PROPERTIES COMPILE_OPTIONS "-w")
+
target_link_libraries(corelib_snippets_eventfilters PRIVATE
Qt::Core
)
diff --git a/src/corelib/doc/snippets/qmetaobject-invokable/CMakeLists.txt b/src/corelib/doc/snippets/qmetaobject-invokable/CMakeLists.txt
index 6ddfd80c036..972bf43d9b1 100644
--- a/src/corelib/doc/snippets/qmetaobject-invokable/CMakeLists.txt
+++ b/src/corelib/doc/snippets/qmetaobject-invokable/CMakeLists.txt
@@ -4,6 +4,8 @@ endif()
add_library(corelib_snippets_qmetaobject-invokable OBJECT)
+set_target_properties(corelib_snippets_qmetaobject-invokable PROPERTIES COMPILE_OPTIONS "-w")
+
target_link_libraries(corelib_snippets_qmetaobject-invokable PRIVATE
Qt::Core
)
diff --git a/src/corelib/doc/snippets/qmetaobject-revision/CMakeLists.txt b/src/corelib/doc/snippets/qmetaobject-revision/CMakeLists.txt
index d760ed225aa..369b2e15315 100644
--- a/src/corelib/doc/snippets/qmetaobject-revision/CMakeLists.txt
+++ b/src/corelib/doc/snippets/qmetaobject-revision/CMakeLists.txt
@@ -4,6 +4,8 @@ endif()
add_library(corelib_snippets_qmetaobject-revision OBJECT)
+set_target_properties(corelib_snippets_qmetaobject-revision PROPERTIES COMPILE_OPTIONS "-w")
+
target_link_libraries(corelib_snippets_qmetaobject-revision PRIVATE
Qt::Core
)
diff --git a/src/corelib/doc/snippets/qprocess/CMakeLists.txt b/src/corelib/doc/snippets/qprocess/CMakeLists.txt
index 7ed0e0b2f68..d00e051ed9b 100644
--- a/src/corelib/doc/snippets/qprocess/CMakeLists.txt
+++ b/src/corelib/doc/snippets/qprocess/CMakeLists.txt
@@ -5,6 +5,8 @@ add_library(corelib_snippets_qprocess OBJECT
qprocess-simpleexecution.cpp
)
+set_target_properties(corelib_snippets_qprocess PROPERTIES COMPILE_OPTIONS "-w")
+
target_link_libraries(corelib_snippets_qprocess PRIVATE
Qt::Core
)
diff --git a/src/corelib/doc/src/objectmodel/objecttrees.qdoc b/src/corelib/doc/src/objectmodel/objecttrees.qdoc
index 8939a534d40..25245fd5de8 100644
--- a/src/corelib/doc/src/objectmodel/objecttrees.qdoc
+++ b/src/corelib/doc/src/objectmodel/objecttrees.qdoc
@@ -59,7 +59,9 @@
behavior applies. Normally, the order of destruction still doesn't
present a problem. Consider the following snippet:
- \snippet code/doc_src_objecttrees.cpp 0
+ \snippet code/doc_src_objecttrees.cpp open
+ \snippet code/doc_src_objecttrees.cpp example1
+ \snippet code/doc_src_objecttrees.cpp close
The parent, \c window, and the child, \c quit, are both \l {QObject}
{QObjects} because QPushButton inherits QWidget, and QWidget inherits
@@ -73,7 +75,9 @@
But now consider what happens if we swap the order of construction, as
shown in this second snippet:
- \snippet code/doc_src_objecttrees.cpp 1
+ \snippet code/doc_src_objecttrees.cpp open
+ \snippet code/doc_src_objecttrees.cpp example2
+ \snippet code/doc_src_objecttrees.cpp close
In this case, the order of destruction causes a problem. The parent's
destructor is called first because it was created last. It then calls
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h
index 71e183e646e..38d1091ac1f 100644
--- a/src/corelib/tools/qarraydata.h
+++ b/src/corelib/tools/qarraydata.h
@@ -39,7 +39,7 @@ struct QArrayData
};
Q_DECLARE_FLAGS(ArrayOptions, ArrayOption)
- QBasicAtomicInt m_ref;
+ QBasicAtomicInt ref_;
ArrayOptions flags;
qsizetype alloc;
@@ -56,19 +56,19 @@ struct QArrayData
/// Returns true if sharing took place
bool ref() noexcept
{
- m_ref.ref();
+ ref_.ref();
return true;
}
/// Returns false if deallocation is necessary
bool deref() noexcept
{
- return m_ref.deref();
+ return ref_.deref();
}
bool isShared() const noexcept
{
- return m_ref.loadRelaxed() != 1;
+ return ref_.loadRelaxed() != 1;
}
// Returns true if a detach is necessary before modifying the data
@@ -76,7 +76,7 @@ struct QArrayData
// detaching is necessary, you should be in a non-const function already
bool needsDetach() noexcept
{
- return m_ref.loadRelaxed() > 1;
+ return ref_.loadRelaxed() > 1;
}
qsizetype detachCapacity(qsizetype newSize) const noexcept
diff --git a/src/corelib/tools/qarraydataops.h b/src/corelib/tools/qarraydataops.h
index 419585b0260..c20abd12c23 100644
--- a/src/corelib/tools/qarraydataops.h
+++ b/src/corelib/tools/qarraydataops.h
@@ -82,7 +82,7 @@ public:
void destroyAll() noexcept // Call from destructors, ONLY!
{
Q_ASSERT(this->d);
- Q_ASSERT(this->d->m_ref.loadRelaxed() == 0);
+ Q_ASSERT(this->d->ref_.loadRelaxed() == 0);
// As this is to be called only from destructor, it doesn't need to be
// exception safe; size not updated.
@@ -345,7 +345,7 @@ public:
// As this is to be called only from destructor, it doesn't need to be
// exception safe; size not updated.
- Q_ASSERT(this->d->m_ref.loadRelaxed() == 0);
+ Q_ASSERT(this->d->ref_.loadRelaxed() == 0);
std::destroy(this->begin(), this->end());
}
diff --git a/src/plugins/platforms/cocoa/qcocoaclipboard.mm b/src/plugins/platforms/cocoa/qcocoaclipboard.mm
index 241faadbec0..0b84cae956b 100644
--- a/src/plugins/platforms/cocoa/qcocoaclipboard.mm
+++ b/src/plugins/platforms/cocoa/qcocoaclipboard.mm
@@ -3,6 +3,7 @@
#include "qcocoaclipboard.h"
+#include <QtGui/qguiapplication.h>
#include <QtGui/qutimimeconverter.h>
#ifndef QT_NO_CLIPBOARD
diff --git a/src/plugins/platforms/cocoa/qcocoacursor.h b/src/plugins/platforms/cocoa/qcocoacursor.h
index 82c03573763..5c8aaeb1fde 100644
--- a/src/plugins/platforms/cocoa/qcocoacursor.h
+++ b/src/plugins/platforms/cocoa/qcocoacursor.h
@@ -4,9 +4,10 @@
#ifndef QWINDOWSCURSOR_H
#define QWINDOWSCURSOR_H
-#include <QtCore>
#include <qpa/qplatformcursor.h>
+#include <QtCore/qhash.h>
+
Q_FORWARD_DECLARE_OBJC_CLASS(NSCursor);
QT_BEGIN_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoadrag.h b/src/plugins/platforms/cocoa/qcocoadrag.h
index c5c126ecf3e..09ba685078b 100644
--- a/src/plugins/platforms/cocoa/qcocoadrag.h
+++ b/src/plugins/platforms/cocoa/qcocoadrag.h
@@ -4,16 +4,12 @@
#ifndef QCOCOADRAG_H
#define QCOCOADRAG_H
-#include <QtGui>
#include <qpa/qplatformdrag.h>
-#include <private/qsimpledrag_p.h>
+#include <QtGui/private/qsimpledrag_p.h>
+#include <QtGui/private/qinternalmimedata_p.h>
#include <QtCore/private/qcore_mac_p.h>
-#include <QtGui/private/qdnd_p.h>
-#include <QtGui/private/qinternalmimedata_p.h>
-
-#include <QtCore/qeventloop.h>
Q_FORWARD_DECLARE_OBJC_CLASS(NSView);
Q_FORWARD_DECLARE_OBJC_CLASS(NSEvent);
@@ -21,6 +17,10 @@ Q_FORWARD_DECLARE_OBJC_CLASS(NSPasteboard);
QT_BEGIN_NAMESPACE
+class QDrag;
+class QEventLoop;
+class QMimeData;
+
class QCocoaDrag : public QPlatformDrag
{
public:
diff --git a/src/plugins/platforms/cocoa/qcocoadrag.mm b/src/plugins/platforms/cocoa/qcocoadrag.mm
index 64df903edcb..0f9df3f17ab 100644
--- a/src/plugins/platforms/cocoa/qcocoadrag.mm
+++ b/src/plugins/platforms/cocoa/qcocoadrag.mm
@@ -7,8 +7,15 @@
#include "qcocoadrag.h"
#include "qmacclipboard.h"
#include "qcocoahelpers.h"
-#include <QtGui/private/qcoregraphics_p.h>
+
+#include <QtGui/qfont.h>
+#include <QtGui/qfontmetrics.h>
+#include <QtGui/qpainter.h>
#include <QtGui/qutimimeconverter.h>
+#include <QtGui/private/qcoregraphics_p.h>
+#include <QtGui/private/qdnd_p.h>
+
+#include <QtCore/qeventloop.h>
#include <QtCore/private/qcore_mac_p.h>
#include <vector>
diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm
index 7ef958e5d9b..a569ce2ba4d 100644
--- a/src/plugins/platforms/cocoa/qcocoahelpers.mm
+++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm
@@ -8,8 +8,6 @@
#include "qcocoahelpers.h"
#include "qnsview.h"
-#include <QtCore>
-#include <QtGui>
#include <qpa/qplatformscreen.h>
#include <private/qguiapplication_p.h>
#include <private/qwindow_p.h>
diff --git a/src/plugins/platforms/cocoa/qmacclipboard.h b/src/plugins/platforms/cocoa/qmacclipboard.h
index 95267565f2d..dcc300797c9 100644
--- a/src/plugins/platforms/cocoa/qmacclipboard.h
+++ b/src/plugins/platforms/cocoa/qmacclipboard.h
@@ -4,10 +4,10 @@
#ifndef QMACCLIPBOARD_H
#define QMACCLIPBOARD_H
-#include <QtGui>
#include <QtGui/qutimimeconverter.h>
#include <QtCore/qpointer.h>
+#include <QtCore/qvariant.h>
#include <ApplicationServices/ApplicationServices.h>
diff --git a/src/plugins/platforms/cocoa/qmacclipboard.mm b/src/plugins/platforms/cocoa/qmacclipboard.mm
index edafa3b6a10..155c4aa826d 100644
--- a/src/plugins/platforms/cocoa/qmacclipboard.mm
+++ b/src/plugins/platforms/cocoa/qmacclipboard.mm
@@ -11,6 +11,7 @@
#include <QtGui/qbitmap.h>
#include <QtCore/qdatetime.h>
#include <QtCore/qmetatype.h>
+#include <QtCore/qmimedata.h>
#include <QtCore/qdebug.h>
#include <QtCore/private/qcore_mac_p.h>
#include <QtGui/qguiapplication.h>
diff --git a/src/plugins/platforms/cocoa/qmultitouch_mac_p.h b/src/plugins/platforms/cocoa/qmultitouch_mac_p.h
index d47d37729f5..63647246589 100644
--- a/src/plugins/platforms/cocoa/qmultitouch_mac_p.h
+++ b/src/plugins/platforms/cocoa/qmultitouch_mac_p.h
@@ -15,13 +15,12 @@
#ifndef QMULTITOUCH_MAC_P_H
#define QMULTITOUCH_MAC_P_H
-#include <QtCore/qglobal.h>
-#include <qpa/qwindowsysteminterface.h>
-#include <qhash.h>
-#include <QtCore>
+#include <QtCore/qhash.h>
+#include <QtCore/private/qcore_mac_p.h>
+
#include <QtGui/qpointingdevice.h>
-#include <QtCore/private/qcore_mac_p.h>
+#include <qpa/qwindowsysteminterface.h>
Q_FORWARD_DECLARE_OBJC_CLASS(NSTouch);
QT_FORWARD_DECLARE_OBJC_ENUM(NSTouchPhase, unsigned long);
diff --git a/src/plugins/platforms/cocoa/qnsview_dragging.mm b/src/plugins/platforms/cocoa/qnsview_dragging.mm
index b4c82ddc0d8..805cc7d59ea 100644
--- a/src/plugins/platforms/cocoa/qnsview_dragging.mm
+++ b/src/plugins/platforms/cocoa/qnsview_dragging.mm
@@ -3,6 +3,8 @@
// This file is included from qnsview.mm, and only used to organize the code
+#include <QtGui/qdrag.h>
+
@implementation QNSView (Dragging)
-(void)registerDragTypes