summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/android/REUSE.toml8
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/QtView.java2
-rw-r--r--src/corelib/animation/qpropertyanimation.cpp7
-rw-r--r--src/corelib/doc/snippets/CMakeLists.txt3
-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/code/src_corelib_animation_qparallelanimationgroup.cpp17
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp151
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_animation_qsequentialanimationgroup.cpp5
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_animation_qvariantanimation.cpp20
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_concurrent_qthreadpool.cpp15
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp966
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_global_qlogging.cpp3
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_global_qnumeric.cpp17
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_global_qoperatingsystemversion.cpp25
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_global_qrandom.cpp194
-rw-r--r--src/corelib/doc/snippets/eventfilters/CMakeLists.txt10
-rw-r--r--src/corelib/doc/snippets/qmetaobject-invokable/CMakeLists.txt8
-rw-r--r--src/corelib/doc/snippets/qmetaobject-revision/CMakeLists.txt8
-rw-r--r--src/corelib/doc/snippets/qprocess/CMakeLists.txt6
-rw-r--r--src/corelib/doc/snippets/qsignalmapper/CMakeLists.txt18
-rw-r--r--src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp65
-rw-r--r--src/corelib/doc/snippets/qsignalmapper/buttonwidget.h4
-rw-r--r--src/corelib/doc/src/animation.qdoc20
-rw-r--r--src/corelib/doc/src/objectmodel/objecttrees.qdoc8
-rw-r--r--src/corelib/global/qassert.cpp8
-rw-r--r--src/corelib/global/qforeach.qdoc2
-rw-r--r--src/corelib/io/qdebug.cpp18
-rw-r--r--src/corelib/io/qdirlisting.cpp18
-rw-r--r--src/corelib/io/qfilesystemengine.cpp1
-rw-r--r--src/corelib/io/qfilesystemengine_mac.mm1
-rw-r--r--src/corelib/io/qfilesystemengine_p.h1
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp1
-rw-r--r--src/corelib/io/qfilesystemengine_win.cpp1
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp11
-rw-r--r--src/corelib/kernel/qmetaobject.cpp51
-rw-r--r--src/corelib/kernel/qobject.cpp162
-rw-r--r--src/corelib/kernel/qobject_p.h60
-rw-r--r--src/corelib/kernel/qsignalmapper.cpp10
-rw-r--r--src/corelib/kernel/qsystemerror.cpp4
-rw-r--r--src/corelib/serialization/qtextstream.cpp6
-rw-r--r--src/corelib/serialization/qtextstream_p.h2
-rw-r--r--src/corelib/tools/qarraydata.h10
-rw-r--r--src/corelib/tools/qarraydataops.h4
-rw-r--r--src/corelib/tools/qduplicatetracker_p.h6
-rw-r--r--src/dbus/qdbusargument.h6
-rw-r--r--src/gui/kernel/qsurfaceformat.cpp4
-rw-r--r--src/gui/painting/qpainterpath.cpp24
-rw-r--r--src/gui/painting/qpainterpath.h5
-rw-r--r--src/gui/painting/qpainterpath_p.h1
-rw-r--r--src/gui/util/qgridlayoutengine.cpp1
-rw-r--r--src/network/kernel/qnetworkproxy_android.cpp3
-rw-r--r--src/plugins/platforms/android/androidcontentfileengine.cpp2
-rw-r--r--src/plugins/platforms/android/extract.cpp1
-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
-rw-r--r--src/plugins/platforms/ios/qiosapplicationdelegate.mm27
-rw-r--r--src/plugins/platforms/ios/qiosglobal.mm2
-rw-r--r--src/plugins/platforms/ios/qiosinputcontext.mm6
-rw-r--r--src/plugins/platforms/ios/qiosviewcontroller.h4
-rw-r--r--src/plugins/platforms/ios/qiosviewcontroller.mm53
-rw-r--r--src/plugins/styles/modernwindows/qwindows11style.cpp94
-rw-r--r--src/widgets/dialogs/qmessagebox.cpp4
-rw-r--r--src/widgets/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp6
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp6
-rw-r--r--src/widgets/widgets/qtoolbararealayout.cpp8
83 files changed, 2309 insertions, 1509 deletions
diff --git a/src/android/REUSE.toml b/src/android/REUSE.toml
index b4734ffee84..04b82f125e9 100644
--- a/src/android/REUSE.toml
+++ b/src/android/REUSE.toml
@@ -1,7 +1,7 @@
version = 1
[[annotations]]
-path = ["jar/build.gradle", "jar/settings.gradle", "templates/build.gradle", "templates_cmake/**"]
+path = ["jar/build.gradle", "jar/settings.gradle", "templates/build.gradle", "templates_cmake/**", "templates_aar/**", "templates/**", "**.xml"]
precedence = "closest"
comment = "double check"
SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd."
@@ -13,3 +13,9 @@ comment = "documentation"
precedence = "closest"
SPDX-FileCopyrightText = "Copyright (C) The Qt Company Ltd."
SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only"
+
+[[annotations]]
+path = ["**.gitignore"]
+precedence = "closest"
+SPDX-FileCopyrightText = "Copyright (C) 2024 The Qt Company Ltd."
+SPDX-License-Identifier = "LicenseRef-Qt-Commercial OR BSD-3-Clause"
diff --git a/src/android/jar/src/org/qtproject/qt/android/QtView.java b/src/android/jar/src/org/qtproject/qt/android/QtView.java
index 9d7850cb517..afe4d005402 100644
--- a/src/android/jar/src/org/qtproject/qt/android/QtView.java
+++ b/src/android/jar/src/org/qtproject/qt/android/QtView.java
@@ -1,6 +1,6 @@
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-// Qt-Security score:critical reason:executing-external-code
+// Qt-Security score:critical reason:execute-external-code
package org.qtproject.qt.android;
diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp
index b4c6b6ff8a6..73ce8ca02c1 100644
--- a/src/corelib/animation/qpropertyanimation.cpp
+++ b/src/corelib/animation/qpropertyanimation.cpp
@@ -21,7 +21,12 @@
makes it possible to animate many of Qt's widgets. Let's look at
an example:
- \snippet code/src_corelib_animation_qpropertyanimation.cpp 0
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp includes
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp class_decl
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp ctor_impl
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp first_example
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp ctor_close
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp main
\note You can also control an animation's lifespan by choosing a
\l{QAbstractAnimation::DeletionPolicy}{delete policy} while starting the
diff --git a/src/corelib/doc/snippets/CMakeLists.txt b/src/corelib/doc/snippets/CMakeLists.txt
index 937433f2e21..78cd4f6b001 100644
--- a/src/corelib/doc/snippets/CMakeLists.txt
+++ b/src/corelib/doc/snippets/CMakeLists.txt
@@ -39,6 +39,7 @@ qt_internal_extend_target(corelib_snippets CONDITION QT_FEATURE_widgets
hellotrmain.cpp
fileinfo/main.cpp
pointer/pointer.cpp
+ qsignalmapper/buttonwidget.cpp
qsortfilterproxymodel-details/main.cpp
qstring/main.cpp
qtcast/qtcast.cpp
@@ -53,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/code/src_corelib_animation_qparallelanimationgroup.cpp b/src/corelib/doc/snippets/code/src_corelib_animation_qparallelanimationgroup.cpp
index 6328cb00119..db3a9ee2dc0 100644
--- a/src/corelib/doc/snippets/code/src_corelib_animation_qparallelanimationgroup.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_animation_qparallelanimationgroup.cpp
@@ -1,10 +1,15 @@
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [0]
- QParallelAnimationGroup *group = new QParallelAnimationGroup;
- group->addAnimation(anim1);
- group->addAnimation(anim2);
+#include <QParallelAnimationGroup>
- group->start();
-//! [0]
+void example(QAbstractAnimation *anim1, QAbstractAnimation *anim2)
+{
+ //! [0]
+ QParallelAnimationGroup *group = new QParallelAnimationGroup;
+ group->addAnimation(anim1);
+ group->addAnimation(anim2);
+
+ group->start();
+ //! [0]
+}
diff --git a/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp b/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp
index 4b77ab607db..7f259e99fb8 100644
--- a/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp
@@ -1,28 +1,102 @@
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QParallelAnimationGroup>
+#include <QSequentialAnimationGroup>
-//! [0]
+//! [includes]
#include <QApplication>
#include <QPushButton>
#include <QPropertyAnimation>
+//![includes]
+
+//! [class_decl]
class MyButtonWidget : public QWidget
{
public:
MyButtonWidget(QWidget *parent = nullptr);
};
+//! [class_decl]
+
+//! [ctor_impl]
MyButtonWidget::MyButtonWidget(QWidget *parent) : QWidget(parent)
{
- QPushButton *button = new QPushButton(tr("Animated Button"), this);
- QPropertyAnimation *anim = new QPropertyAnimation(button, "pos", this);
- anim->setDuration(10000);
- anim->setStartValue(QPoint(0, 0));
- anim->setEndValue(QPoint(100, 250));
- anim->start();
+//![ctor_impl]
+ {
+ //! [first_example]
+ QPushButton *button = new QPushButton(tr("Animated Button"), this);
+ QPropertyAnimation *anim = new QPropertyAnimation(button, "pos", this);
+ anim->setDuration(10000);
+ anim->setStartValue(QPoint(0, 0));
+ anim->setEndValue(QPoint(100, 250));
+ anim->start();
+ //! [first_example]
+ }
+
+ {
+ //! [easing-curve]
+ QPushButton *button = new QPushButton(tr("Animated Button"), this);
+ QPropertyAnimation *anim = new QPropertyAnimation(button, "pos", this);
+ anim->setDuration(10000);
+ anim->setStartValue(QPoint(0, 0));
+ anim->setEndValue(QPoint(100, 250));
+ anim->setEasingCurve(QEasingCurve::OutBounce);
+ anim->start();
+ //! [easing-curve]
+ }
+
+ {
+ //! [animation-group1]
+ QPushButton *bonnie = new QPushButton(tr("Bonnie"), this);
+ QPushButton *clyde = new QPushButton(tr("Clyde"), this);
+
+ QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "pos", this);
+ anim1->setDuration(3000);
+ anim1->setStartValue(QPoint(0, 0));
+ anim1->setEndValue(QPoint(100, 250));
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "pos", this);
+ anim2->setDuration(3000);
+ anim2->setStartValue(QPoint(100, 250));
+ anim2->setEndValue(QPoint(500, 500));
+
+ QParallelAnimationGroup *parallelAnim = new QParallelAnimationGroup;
+ parallelAnim->addAnimation(anim1);
+ parallelAnim->addAnimation(anim2);
+ parallelAnim->start();
+ //! [animation-group1]
+ }
+
+ {
+ //! [animation-group2]
+ QPushButton *bonnie = new QPushButton(tr("Bonnie"), this);
+ QPushButton *clyde = new QPushButton(tr("Clyde"), this);
+
+ QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "pos", this);
+ anim1->setDuration(3000);
+ anim1->setStartValue(QPoint(0, 0));
+ anim1->setEndValue(QPoint(100, 250));
+
+ QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "pos", this);
+ anim2->setDuration(3000);
+ anim2->setStartValue(QPoint(0, 0));
+ anim2->setEndValue(QPoint(200, 250));
+
+ QSequentialAnimationGroup *sequenceAnim = new QSequentialAnimationGroup;
+ sequenceAnim->addAnimation(anim1);
+ sequenceAnim->addAnimation(anim2);
+ sequenceAnim->start();
+ //! [animation-group2]
+ }
+
+//! [ctor_close]
}
+//! [ctor_close]
+
+//! [main]
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
@@ -31,65 +105,4 @@ int main(int argc, char *argv[])
buttonAnimWidget.show();
return a.exec();
}
-//! [0]
-
-
-//! [easing-curve]
-MyButtonWidget::MyButtonWidget(QWidget *parent) : QWidget(parent)
-{
- QPushButton *button = new QPushButton(tr("Animated Button"), this);
- QPropertyAnimation *anim = new QPropertyAnimation(button, "pos", this);
- anim->setDuration(10000);
- anim->setStartValue(QPoint(0, 0));
- anim->setEndValue(QPoint(100, 250));
- anim->setEasingCurve(QEasingCurve::OutBounce);
- anim->start();
-}
-//! [easing-curve]
-
-
-//! [animation-group1]
-MyButtonWidget::MyButtonWidget(QWidget *parent) : QWidget(parent)
-{
- QPushButton *bonnie = new QPushButton(tr("Bonnie"), this);
- QPushButton *clyde = new QPushButton(tr("Clyde"), this);
-
- QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "pos", this);
- anim1->setDuration(3000);
- anim1->setStartValue(QPoint(0, 0));
- anim1->setEndValue(QPoint(100, 250));
-
- QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "pos", this);
- anim2->setDuration(3000);
- anim2->setStartValue(QPoint(100, 250));
- anim2->setEndValue(QPoint(500, 500));
-
- QParallelAnimationGroup *parallelAnim = new QParallelAnimationGroup;
- parallelAnim->addAnimation(anim1);
- parallelAnim->addAnimation(anim2);
- parallelAnim->start();
-}
-//! [animation-group1]
-
-//! [animation-group2]
-MyButtonWidget::MyButtonWidget(QWidget *parent) : QWidget(parent)
-{
- QPushButton *bonnie = new QPushButton(tr("Bonnie"), this);
- QPushButton *clyde = new QPushButton(tr("Clyde"), this);
-
- QPropertyAnimation *anim1 = new QPropertyAnimation(bonnie, "pos", this);
- anim1->setDuration(3000);
- anim1->setStartValue(QPoint(0, 0));
- anim1->setEndValue(QPoint(100, 250));
-
- QPropertyAnimation *anim2 = new QPropertyAnimation(clyde, "pos", this);
- anim2->setDuration(3000);
- anim2->setStartValue(QPoint(0, 0));
- anim2->setEndValue(QPoint(200, 250));
-
- QSequentialAnimationGroup *sequenceAnim = new QSequentialAnimationGroup;
- sequenceAnim->addAnimation(anim1);
- sequenceAnim->addAnimation(anim2);
- sequenceAnim->start();
-}
-//! [animation-group2]
+//! [main]
diff --git a/src/corelib/doc/snippets/code/src_corelib_animation_qsequentialanimationgroup.cpp b/src/corelib/doc/snippets/code/src_corelib_animation_qsequentialanimationgroup.cpp
index a429fe20b2d..c00a723a26c 100644
--- a/src/corelib/doc/snippets/code/src_corelib_animation_qsequentialanimationgroup.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_animation_qsequentialanimationgroup.cpp
@@ -1,6 +1,10 @@
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QSequentialAnimationGroup>
+
+void example(QAbstractAnimation *anim1, QAbstractAnimation *anim2)
+{
//! [0]
QSequentialAnimationGroup *group = new QSequentialAnimationGroup;
@@ -9,3 +13,4 @@
group->start();
//! [0]
+}
diff --git a/src/corelib/doc/snippets/code/src_corelib_animation_qvariantanimation.cpp b/src/corelib/doc/snippets/code/src_corelib_animation_qvariantanimation.cpp
index be7f549f655..be7e51e1b44 100644
--- a/src/corelib/doc/snippets/code/src_corelib_animation_qvariantanimation.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_animation_qvariantanimation.cpp
@@ -1,14 +1,22 @@
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QVariantAnimation>
+#include <QColor>
+
//! [0]
- QVariant myColorInterpolator(const QColor &start, const QColor &end, qreal progress)
- {
- ...
- return QColor(...);
- }
- ...
+QVariant myColorInterpolator(const QColor &start, const QColor &end, qreal progress)
+{
+ // ...
+ return QColor(/*...*/);
+}
+// ...
+void someFunc()
+{
+ // ...
qRegisterAnimationInterpolator<QColor>(myColorInterpolator);
+ // ...
+}
//! [0]
//! [1]
diff --git a/src/corelib/doc/snippets/code/src_corelib_concurrent_qthreadpool.cpp b/src/corelib/doc/snippets/code/src_corelib_concurrent_qthreadpool.cpp
index 4cba70e62d4..56a0532ac21 100644
--- a/src/corelib/doc/snippets/code/src_corelib_concurrent_qthreadpool.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_concurrent_qthreadpool.cpp
@@ -1,6 +1,10 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QThreadPool>
+#include <QRunnable>
+#include <QDebug>
+
//! [0]
class HelloWorldTask : public QRunnable
{
@@ -10,7 +14,12 @@ class HelloWorldTask : public QRunnable
}
};
-HelloWorldTask *hello = new HelloWorldTask();
-// QThreadPool takes ownership and deletes 'hello' automatically
-QThreadPool::globalInstance()->start(hello);
+int main()
+{
+ //...
+ HelloWorldTask *hello = new HelloWorldTask();
+ // QThreadPool takes ownership and deletes 'hello' automatically
+ QThreadPool::globalInstance()->start(hello);
+ //...
+}
//! [0]
diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
index a981163a6e7..61621f54911 100644
--- a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
@@ -1,14 +1,21 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [0]
-label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
-label->setAlignment({ });
-//! [0]
-
+#if __has_include(<QLabel>)
+#include <QLabel>
+void label_example()
+{
+ QLabel *label = new QLabel;
+ //! [0]
+ label->setAlignment(Qt::AlignLeft | Qt::AlignTop);
+ label->setAlignment({ });
+ //! [0]
+}
+#endif
+#include <QMetaProperty>
//! [1]
-class MyClass
+class MyClass_1
{
public:
enum Option {
@@ -18,182 +25,226 @@ public:
SqueezeBlank = 0x4
};
Q_DECLARE_FLAGS(Options, Option)
- ...
+ //...
};
-Q_DECLARE_OPERATORS_FOR_FLAGS(MyClass::Options)
+Q_DECLARE_OPERATORS_FOR_FLAGS(MyClass_1::Options)
//! [1]
+#if 0
//! [meta-object flags]
Q_FLAG(Options)
//! [meta-object flags]
+#endif
-//! [2]
-typedef QFlags<Enum> Flags;
-//! [2]
+struct DummyDriver {
+ bool isOpen() const { return true; }
+ bool isOpenError() const { return false; }
+};
-//! [4]
-if (!driver()->isOpen() || driver()->isOpenError()) {
- qWarning("QSqlQuery::exec: database not open");
- return false;
+DummyDriver* driver() {
+ static DummyDriver d;
+ return &d;
}
-//! [4]
-
-
-//! [5]
-qint64 value = Q_INT64_C(932838457459459);
-//! [5]
-
-
-//! [6]
-quint64 value = Q_UINT64_C(932838457459459);
-//! [6]
-
-//! [8]
-qint64 value = Q_INT64_C(932838457459459);
-//! [8]
+bool examples()
+{
+ enum Enum {};
+ //! [2]
+ typedef QFlags<Enum> Flags;
+ //! [2]
-//! [9]
-quint64 value = Q_UINT64_C(932838457459459);
-//! [9]
+ //! [4]
+ if (!driver()->isOpen() || driver()->isOpenError()) {
+ qWarning("QSqlQuery::exec: database not open");
+ return false;
+ }
+ //! [4]
+ {
+ //! [5]
+ qint64 value = Q_INT64_C(932838457459459);
+ //! [5]
+ }
-//! [10]
-int absoluteValue;
-int myValue = -4;
+ {
+ //! [6]
+ quint64 value = Q_UINT64_C(932838457459459);
+ //! [6]
+ }
-absoluteValue = qAbs(myValue);
-// absoluteValue == 4
-//! [10]
+ {
+ //! [8]
+ qint64 value = Q_INT64_C(932838457459459);
+ //! [8]
+ }
+ {
+ //! [9]
+ quint64 value = Q_UINT64_C(932838457459459);
+ //! [9]
+ }
-//! [11A]
-double valueA = 2.3;
-double valueB = 2.7;
+ {
+ //! [10]
+ int absoluteValue;
+ int myValue = -4;
-int roundedValueA = qRound(valueA);
-// roundedValueA = 2
-int roundedValueB = qRound(valueB);
-// roundedValueB = 3
-//! [11A]
+ absoluteValue = qAbs(myValue);
+ // absoluteValue == 4
+ //! [10]
+ }
-//! [11B]
-float valueA = 2.3;
-float valueB = 2.7;
+ {
+ //! [11A]
+ double valueA = 2.3;
+ double valueB = 2.7;
-int roundedValueA = qRound(valueA);
-// roundedValueA = 2
-int roundedValueB = qRound(valueB);
-// roundedValueB = 3
-//! [11B]
+ int roundedValueA = qRound(valueA);
+ // roundedValueA = 2
+ int roundedValueB = qRound(valueB);
+ // roundedValueB = 3
+ //! [11A]
+ }
+ {
+ //! [11B]
+ float valueA = 2.3f;
+ float valueB = 2.7f;
-//! [12A]
-double valueA = 42949672960.3;
-double valueB = 42949672960.7;
+ int roundedValueA = qRound(valueA);
+ // roundedValueA = 2
+ int roundedValueB = qRound(valueB);
+ // roundedValueB = 3
+ //! [11B]
+ }
-qint64 roundedValueA = qRound64(valueA);
-// roundedValueA = 42949672960
-qint64 roundedValueB = qRound64(valueB);
-// roundedValueB = 42949672961
-//! [12A]
+ {
+ //! [12A]
+ double valueA = 42949672960.3;
+ double valueB = 42949672960.7;
-//! [12B]
-float valueA = 42949672960.3;
-float valueB = 42949672960.7;
+ qint64 roundedValueA = qRound64(valueA);
+ // roundedValueA = 42949672960
+ qint64 roundedValueB = qRound64(valueB);
+ // roundedValueB = 42949672961
+ //! [12A]
+ }
-qint64 roundedValueA = qRound64(valueA);
-// roundedValueA = 42949672960
-qint64 roundedValueB = qRound64(valueB);
-// roundedValueB = 42949672961
-//! [12B]
+ {
+ //! [12B]
+ float valueA = 42949672960.3f;
+ float valueB = 42949672960.7f;
+ qint64 roundedValueA = qRound64(valueA);
+ // roundedValueA = 42949672960
+ qint64 roundedValueB = qRound64(valueB);
+ // roundedValueB = 42949672961
+ //! [12B]
+ }
-//! [13]
-int myValue = 6;
-int yourValue = 4;
+ {
+ //! [13]
+ int myValue = 6;
+ int yourValue = 4;
-int minValue = qMin(myValue, yourValue);
-// minValue == yourValue
-//! [13]
+ int minValue = qMin(myValue, yourValue);
+ // minValue == yourValue
+ //! [13]
+ }
+ {
+ //! [14]
+ int myValue = 6;
+ int yourValue = 4;
-//! [14]
-int myValue = 6;
-int yourValue = 4;
+ int maxValue = qMax(myValue, yourValue);
+ // maxValue == myValue
+ //! [14]
+ }
-int maxValue = qMax(myValue, yourValue);
-// maxValue == myValue
-//! [14]
+ {
+ //! [15]
+ int myValue = 10;
+ int minValue = 2;
+ int maxValue = 6;
+ int boundedValue = qBound(minValue, myValue, maxValue);
+ // boundedValue == 6
+ //! [15]
+ }
-//! [15]
-int myValue = 10;
-int minValue = 2;
-int maxValue = 6;
+ return true;
+}
-int boundedValue = qBound(minValue, myValue, maxValue);
-// boundedValue == 6
-//! [15]
+#if __has_include(<QStyle>)
+#include <QStyle>
+QStyle *style()
+{
+ static QStyle *s = nullptr;
+ return s;
+}
-//! [16]
-#if QT_VERSION >= QT_VERSION_CHECK(4, 1, 0)
- QIcon icon = style()->standardIcon(QStyle::SP_TrashIcon);
-#else
- QPixmap pixmap = style()->standardPixmap(QStyle::SP_TrashIcon);
- QIcon icon(pixmap);
+void snippet_16()
+{
+ //! [16]
+ #if QT_VERSION >= QT_VERSION_CHECK(4, 1, 0)
+ QIcon icon = style()->standardIcon(QStyle::SP_TrashIcon);
+ #else
+ QPixmap pixmap = style()->standardPixmap(QStyle::SP_TrashIcon);
+ QIcon icon(pixmap);
+ #endif
+ //! [16]
+}
#endif
-//! [16]
-
-//! [17]
+//! [17&19_include_open]
// File: div.cpp
#include <QtGlobal>
int divide(int a, int b)
{
- Q_ASSERT(b != 0);
- return a / b;
-}
-//! [17]
-
+//! [17&19_include_open]
-//! [18]
-ASSERT: "b != 0" in file div.cpp, line 7
-//! [18]
+ //! [17assert]
+ Q_ASSERT(b != 0);
+ //! [17assert]
+ //! [19assert]
+ Q_ASSERT_X(b != 0, "divide", "division by zero");
+ //! [19assert]
-//! [19]
-// File: div.cpp
-
-#include <QtGlobal>
-
-int divide(int a, int b)
-{
- Q_ASSERT_X(b != 0, "divide", "division by zero");
- return a / b;
+ //! [17&19_return_close]
+ return a / b;
}
-//! [19]
+//! [17&19_return_close]
+#if 0
+//! [18]
+ASSERT: "b != 0" in file div.cpp, line 7
+//! [18]
//! [20]
ASSERT failure in divide: "division by zero", file div.cpp, line 7
//! [20]
+#endif
+#include <QtAssert>
-//! [21]
-int *a;
-
-Q_CHECK_PTR(a = new int[80]); // WRONG!
+void pointer_example()
+{
+ //! [21]
+ int *a;
-a = new (nothrow) int[80]; // Right
-Q_CHECK_PTR(a);
-//! [21]
+ Q_CHECK_PTR(a = new int[80]); // WRONG!
+ a = new (std::nothrow) int[80]; // Right
+ Q_CHECK_PTR(a);
+ //! [21]
+}
//! [22]
template<typename TInputType>
@@ -208,7 +259,7 @@ const TInputType &myMin(const TInputType &value1, const TInputType &value2)
}
//! [22]
-
+# if __has_include(<QWidget>)
//! [23]
#include <QApplication>
#include <stdio.h>
@@ -224,36 +275,44 @@ void logToFile(QtMsgType type, const QMessageLogContext &context, const QString
fflush(f);
if (originalHandler)
- *originalHandler(type, context, msg);
+ originalHandler(type, context, msg);
}
int main(int argc, char **argv)
{
originalHandler = qInstallMessageHandler(logToFile);
QApplication app(argc, argv);
- ...
+ // ...
return app.exec();
}
//! [23]
+#endif
+#include <QBrush>
-//! [24]
-qDebug("Items in list: %d", myList.size());
-//! [24]
+void debug_info_example()
+{
+ QList<int> myList;
+ QBrush myQBrush(Qt::red);
+ int i = 0;
+ //! [24]
+ qDebug("Items in list: %d", myList.size());
+ //! [24]
-//! [25]
-qDebug() << "Brush:" << myQBrush << "Other value:" << i;
-//! [25]
+ //! [25]
+ qDebug() << "Brush:" << myQBrush << "Other value:" << i;
+ //! [25]
-//! [qInfo_printf]
-qInfo("Items in list: %d", myList.size());
-//! [qInfo_printf]
+ //! [qInfo_printf]
+ qInfo("Items in list: %d", myList.size());
+ //! [qInfo_printf]
-//! [qInfo_stream]
-qInfo() << "Brush:" << myQBrush << "Other value:" << i;
-//! [qInfo_stream]
+ //! [qInfo_stream]
+ qInfo() << "Brush:" << myQBrush << "Other value:" << i;
+ //! [qInfo_stream]
+}
//! [26]
void f(int c)
@@ -263,12 +322,16 @@ void f(int c)
}
//! [26]
+void warning_example()
+{
+ QBrush myQBrush(Qt::red);
+ int i = 0;
+ //! [27]
+ qWarning() << "Brush:" << myQBrush << "Other value:" << i;
+ //! [27]
+}
-//! [27]
-qWarning() << "Brush:" << myQBrush << "Other value:" << i;
-//! [27]
-
-
+#include <QFile>
//! [28]
void load(const QString &fileName)
{
@@ -278,14 +341,17 @@ void load(const QString &fileName)
}
//! [28]
-
-//! [29]
-qCritical() << "Brush:" << myQBrush << "Other value:" << i;
-//! [29]
-
+void critical_example()
+{
+ QBrush myQBrush(Qt::red);
+ int i = 0;
+ //! [29]
+ qCritical() << "Brush:" << myQBrush << "Other value:" << i;
+ //! [29]
+}
//! [30]
-int divide(int a, int b)
+int divide_by_zero(int a, int b)
{
if (b == 0) // program error
qFatal("divide: cannot divide by zero");
@@ -293,91 +359,150 @@ int divide(int a, int b)
}
//! [30]
-
-//! [31]
-forever {
- ...
+void forever_example()
+{
+ //! [31]
+ forever {
+ // ...
+ }
+ //! [31]
}
-//! [31]
-
+# if 0
//! [32]
CONFIG += no_keywords
//! [32]
+#endif
+namespace snippet_34
+{
+ class FriendlyConversation
+ {
+ public:
+ QString greeting(int type);
+ };
-//! [33]
-CONFIG += no_keywords
-//! [33]
+ QString tr(const char *)
+ {
+ return "";
+ }
+ //! [34]
+ QString FriendlyConversation::greeting(int type)
+ {
+ static const char *greeting_strings[] = {
+ QT_TR_NOOP("Hello"),
+ QT_TR_NOOP("Goodbye")
+ };
+ return tr(greeting_strings[type]);
+ }
+ //! [34]
+}
-//! [34]
-QString FriendlyConversation::greeting(int type)
+#if __has_include(<QApplication>)
+namespace snippet_35
{
- static const char *greeting_strings[] = {
- QT_TR_NOOP("Hello"),
- QT_TR_NOOP("Goodbye")
+ class FriendlyConversation
+ {
+ public:
+ QString greeting(int type);
};
- return tr(greeting_strings[type]);
-}
-//! [34]
+ QString tr(const char *)
+ {
+ return "";
+ }
-//! [35]
-static const char *greeting_strings[] = {
- QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"),
- QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye")
-};
-QString FriendlyConversation::greeting(int type)
-{
- return tr(greeting_strings[type]);
+ //! [35]
+ static const char *greeting_strings[] = {
+ QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"),
+ QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye")
+ };
+
+ QString FriendlyConversation::greeting(int type)
+ {
+ return tr(greeting_strings[type]);
+ }
+
+ QString global_greeting(int type)
+ {
+ return qApp->translate("FriendlyConversation",
+ greeting_strings[type]);
+ }
+ //! [35]
}
-QString global_greeting(int type)
+namespace snippet_36
{
- return qApp->translate("FriendlyConversation",
- greeting_strings[type]);
-}
-//! [35]
+ class FriendlyConversation
+ {
+ public:
+ QString greeting(int type);
+ };
+ QString tr(const char *text, const char *comment)
+ {
+ return "";
+ }
-//! [36]
-static { const char *source; const char *comment; } greeting_strings[] =
-{
- QT_TRANSLATE_NOOP3("FriendlyConversation", "Hello",
- "A really friendly hello"),
- QT_TRANSLATE_NOOP3("FriendlyConversation", "Goodbye",
- "A really friendly goodbye")
-};
+ //! [36]
-QString FriendlyConversation::greeting(int type)
-{
- return tr(greeting_strings[type].source,
- greeting_strings[type].comment);
+ static struct { const char *source; const char *comment; } greeting_strings[] =
+ {
+ QT_TRANSLATE_NOOP3("FriendlyConversation", "Hello",
+ "A really friendly hello"),
+ QT_TRANSLATE_NOOP3("FriendlyConversation", "Goodbye",
+ "A really friendly goodbye")
+ };
+
+ QString FriendlyConversation::greeting(int type)
+ {
+ return tr(greeting_strings[type].source,
+ greeting_strings[type].comment);
+ }
+
+ QString global_greeting(int type)
+ {
+ return qApp->translate("FriendlyConversation",
+ greeting_strings[type].source,
+ greeting_strings[type].comment);
+ }
+ //! [36]
}
+#endif // __has_include(<QApplication>)
-QString global_greeting(int type)
+namespace snippet_qttrnnoop
{
- return qApp->translate("FriendlyConversation",
- greeting_strings[type].source,
- greeting_strings[type].comment);
-}
-//! [36]
+ class StatusClass
+ {
+ public:
+ static QString status(int type, int count);
+ static const char * const status_strings[];
+ };
+ QString tr(const char *, const char *, int)
+ {
+ return "";
+ }
+ //! [qttrnnoop]
+ const char * const StatusClass::status_strings[] = {
+ QT_TR_N_NOOP("There are %n new message(s)"),
+ QT_TR_N_NOOP("There are %n total message(s)")
+ };
-//! [qttrnnoop]
-static const char * const StatusClass::status_strings[] = {
- QT_TR_N_NOOP("There are %n new message(s)"),
- QT_TR_N_NOOP("There are %n total message(s)")
-};
+ QString StatusClass::status(int type, int count)
+ {
+ return tr(status_strings[type], nullptr, count);
+ }
+ //! [qttrnnoop]
+}
-QString StatusClass::status(int type, int count)
+QString translate(const char *, const char *, const char *, int)
{
- return tr(status_strings[type], nullptr, count);
+ return "";
}
-//! [qttrnnoop]
//! [qttranslatennoop]
static const char * const greeting_strings[] = {
@@ -391,88 +516,125 @@ QString global_greeting(int type, int msgcnt)
}
//! [qttranslatennoop]
-//! [qttranslatennoop3]
-static { const char * const source; const char * const comment; } status_strings[] = {
- QT_TRANSLATE_N_NOOP3("Message Status", "Hello, you have %n message(s)",
- "A login message status"),
- QT_TRANSLATE_N_NOOP3("Message status", "You have %n new message(s)",
- "A new message query status")
-};
-
-QString FriendlyConversation::greeting(int type, int count)
+#if __has_include(<QApplication>)
+namespace snippet_qttranslatennoop3
{
- return tr(status_strings[type].source,
- status_strings[type].comment, count);
-}
+ class FriendlyConversation
+ {
+ public:
+ QString greeting(int type, int count);
+ };
-QString global_greeting(int type, int count)
-{
- return qApp->translate("Message Status",
- status_strings[type].source,
- status_strings[type].comment,
- count);
-}
-//! [qttranslatennoop3]
+ QString tr(const char *text, const char *comment, int n)
+ {
+ return "";
+ }
+ //! [qttranslatennoop3]
+ static struct { const char * const source; const char * const comment; } status_strings[] = {
+ QT_TRANSLATE_N_NOOP3("Message Status", "Hello, you have %n message(s)",
+ "A login message status"),
+ QT_TRANSLATE_N_NOOP3("Message status", "You have %n new message(s)",
+ "A new message query status")
+ };
-//! [qttrid]
+ QString FriendlyConversation::greeting(int type, int count)
+ {
+ return tr(status_strings[type].source,
+ status_strings[type].comment, count);
+ }
+
+ QString global_greeting(int type, int count)
+ {
+ return qApp->translate("Message Status",
+ status_strings[type].source,
+ status_strings[type].comment,
+ count);
+ }
+ //! [qttranslatennoop3]
+}
+#endif // __has_include(<QApplication>)
+
+void qttrid_example()
+{
+ int n = 0;
+ //! [qttrid]
//% "%n fooish bar(s) found.\n"
//% "Do you want to continue?"
QString text = qtTrId("qtn_foo_bar", n);
-//! [qttrid]
+ //! [qttrid]
+}
+#if __has_include(<QWidget>)
+namespace qttrid_noop
+{
+ class TheClass : public QWidget
+ {
+ public:
+ TheClass(QWidget *parent = nullptr) : QWidget(parent) {
+ addLabels();
+ }
+ void addLabels();
+ };
-//! [qttrid_noop]
-static const char * const ids[] = {
- //% "This is the first text."
- QT_TRID_NOOP("qtn_1st_text"),
- //% "This is the second text."
- QT_TRID_NOOP("qtn_2nd_text"),
- 0
-};
+ //! [qttrid_noop]
+ static const char * const ids[] = {
+ //% "This is the first text."
+ QT_TRID_NOOP("qtn_1st_text"),
+ //% "This is the second text."
+ QT_TRID_NOOP("qtn_2nd_text"),
+ 0
+ };
-void TheClass::addLabels()
-{
- for (int i = 0; ids[i]; ++i)
- new QLabel(qtTrId(ids[i]), this);
+ void TheClass::addLabels()
+ {
+ for (int i = 0; ids[i]; ++i)
+ new QLabel(qtTrId(ids[i]), this);
+ }
+ //! [qttrid_noop]
}
-//! [qttrid_noop]
-
-//! [qttrid_n_noop]
-static const char * const ids[] = {
- //% "%n foo(s) found."
- QT_TRID_N_NOOP("qtn_foo"),
- //% "%n bar(s) found."
- QT_TRID_N_NOOP("qtn_bar"),
- 0
-};
+#endif
-QString result(int type, int n)
+namespace qttrid_n_noop
{
- return qtTrId(ids[type], n);
+ //! [qttrid_n_noop]
+ static const char * const ids[] = {
+ //% "%n foo(s) found."
+ QT_TRID_N_NOOP("qtn_foo"),
+ //% "%n bar(s) found."
+ QT_TRID_N_NOOP("qtn_bar"),
+ 0
+ };
+
+ QString result(int type, int n)
+ {
+ return qtTrId(ids[type], n);
+ }
+ //! [qttrid_n_noop]
}
-//! [qttrid_n_noop]
-//! [38]
-struct Point2D
+namespace for_struct
{
- int x;
- int y;
-};
-
-Q_DECLARE_TYPEINFO(Point2D, Q_PRIMITIVE_TYPE);
-//! [38]
+ //! [38]
+ struct Point2D
+ {
+ int x;
+ int y;
+ };
+ Q_DECLARE_TYPEINFO(Point2D, Q_PRIMITIVE_TYPE);
+ //! [38]
+}
//! [39]
class Point2D
{
public:
Point2D() { data = new int[2]; }
- Point2D(const Point2D &other) { ... }
+ Point2D(const Point2D &other) { /*...*/ }
~Point2D() { delete[] data; }
- Point2D &operator=(const Point2D &other) { ... }
+ Point2D &operator=(const Point2D &other) { /*...*/ }
int x() const { return data[0]; }
int y() const { return data[1]; }
@@ -487,13 +649,13 @@ Q_DECLARE_TYPEINFO(Point2D, Q_RELOCATABLE_TYPE);
//! [40]
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
-...
+//...
#endif
-or
+//or
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
-...
+//...
#endif
//! [40]
@@ -502,7 +664,7 @@ or
//! [41]
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
-...
+//...
#endif
//! [41]
@@ -510,7 +672,7 @@ or
//! [42]
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
-...
+//...
#endif
//! [42]
@@ -523,14 +685,17 @@ namespace QT_NAMESPACE {
}
//! [end namespace macro]
-//! [43]
-class MyClass : public QObject
+namespace snippet_43
{
-private:
- Q_DISABLE_COPY(MyClass)
-};
+ //! [43]
+ class MyClass : public QObject
+ {
+ private:
+ Q_DISABLE_COPY(MyClass)
+ };
-//! [43]
+ //! [43]
+}
//! [44]
class MyClass : public QObject
@@ -541,25 +706,33 @@ private:
};
//! [44]
-//! [45]
-QWidget w = QWidget();
-//! [45]
+#if __has_include(<QWidget>)
+void qwidget_example()
+{
+ //! [45]
+ QWidget w = QWidget();
+ //! [45]
+}
+#endif
-//! [46]
-// Instead of comparing with 0.0
-qFuzzyCompare(0.0, 1.0e-200); // This will return false
-// Compare adding 1 to both values will fix the problem
-qFuzzyCompare(1 + 0.0, 1 + 1.0e-200); // This will return true
-//! [46]
+void qfuzzycompare_example()
+{
+ //! [46]
+ // Instead of comparing with 0.0
+ qFuzzyCompare(0.0, 1.0e-200); // This will return false
+ // Compare adding 1 to both values will fix the problem
+ qFuzzyCompare(1 + 0.0, 1 + 1.0e-200); // This will return true
+ //! [46]
+}
//! [49]
void myMessageHandler(QtMsgType, const QMessageLogContext &, const QString &);
//! [49]
//! [50]
-class B {...};
-class C {...};
-class D {...};
+class B {/*...*/};
+class C {/*...*/};
+class D {/*...*/};
struct A : public B {
C c;
D d;
@@ -570,33 +743,45 @@ struct A : public B {
template<> class QTypeInfo<A> : public QTypeInfoMerger<A, B, C, D> {};
//! [51]
-//! [52]
+namespace snippet_52
+{
+ //! [52]
struct Foo {
void overloadedFunction();
void overloadedFunction(int, const QString &);
};
- ... qOverload<>(&Foo::overloadedFunction)
- ... qOverload<int, const QString &>(&Foo::overloadedFunction)
-//! [52]
+ auto ptr_1 = qOverload<>(&Foo::overloadedFunction);
+ auto ptr_2 = qOverload<int, const QString &>(&Foo::overloadedFunction);
+ //! [52]
+}
+
//! [54]
struct Foo {
void overloadedFunction(int, const QString &);
void overloadedFunction(int, const QString &) const;
};
- ... qConstOverload<int, const QString &>(&Foo::overloadedFunction)
- ... qNonConstOverload<int, const QString &>(&Foo::overloadedFunction)
+ auto ptr_1 = qConstOverload<int, const QString &>(&Foo::overloadedFunction);
+ auto ptr_2 = qNonConstOverload<int, const QString &>(&Foo::overloadedFunction);
//! [54]
-//! [qlikely]
- // the condition inside the "if" will be successful most of the times
- for (int i = 1; i <= 365; i++) {
- if (Q_LIKELY(isWorkingDay(i))) {
- ...
+bool isWorkingDay(int day)
+{
+ return false;
+}
+
+void qlikely_example()
+{
+ //! [qlikely]
+ // the condition inside the "if" will be successful most of the times
+ for (int i = 1; i <= 365; i++) {
+ if (Q_LIKELY(isWorkingDay(i))) {
+ //...
+ }
+ //...
}
- ...
- }
-//! [qlikely]
+ //! [qlikely]
+}
//! [qunlikely]
bool readConfiguration(const QFile &file)
@@ -607,7 +792,7 @@ bool readConfiguration(const QFile &file)
return false;
}
- ...
+ //...
return true;
}
//! [qunlikely]
@@ -621,20 +806,29 @@ bool readConfiguration(const QFile &file)
};
//! [qunreachable-enum]
-//! [qunreachable-switch]
- switch (shape) {
- case Rectangle:
- return rectangle();
- case Triangle:
- return triangle();
- case Circle:
- return circle();
- case NumShapes:
- Q_UNREACHABLE();
- break;
- }
-//! [qunreachable-switch]
+int rectangle() { return 0; }
+int triangle() { return 1; }
+int circle() { return 2; }
+
+int qunreachable_example(Shapes shape)
+{
+ //! [qunreachable-switch]
+ switch (shape) {
+ case Rectangle:
+ return rectangle();
+ case Triangle:
+ return triangle();
+ case Circle:
+ return circle();
+ case NumShapes:
+ Q_UNREACHABLE();
+ break;
+ }
+ //! [qunreachable-switch]
+ return -1;
+}
+# if __has_include(<QWidget>)
//! [qt-version-check]
#include <QtGlobal>
@@ -644,68 +838,94 @@ bool readConfiguration(const QFile &file)
#include <QtGui>
#endif
//! [qt-version-check]
+#endif
+
+void qgetenv_examples()
+{
+ const char *varName = "MY_ENV_VAR";
+ bool *ok = nullptr;
+
+ //! [is-empty]
+ bool is_empty = qgetenv(varName).isEmpty();
+ //! [is-empty]
+
+ //! [to-int]
+ int to_int = qgetenv(varName).toInt(ok, 0);
+ //! [to-int]
-//! [is-empty]
- qgetenv(varName).isEmpty()
-//! [is-empty]
-
-//! [to-int]
- qgetenv(varName).toInt(ok, 0)
-//! [to-int]
-
-//! [int-value_or]
- qEnvironmentVariableIntegerValue(varName).value_or(0)
-//! [int-value_or]
-
-//! [int-eq0]
- qEnvironmentVariableIntegerValue(varName) == 0
-//! [int-eq0]
-
-//! [is-null]
- !qgetenv(varName).isNull()
-//! [is-null]
-
-//! [as-const-0]
- QString s = ...;
- for (QChar ch : s) // detaches 's' (performs a deep-copy if 's' was shared)
- process(ch);
- for (QChar ch : qAsConst(s)) // ok, no detach attempt
- process(ch);
-//! [as-const-0]
-
-//! [as-const-1]
- const QString s = ...;
- for (QChar ch : s) // ok, no detach attempt on const objects
- process(ch);
-//! [as-const-1]
-
-//! [as-const-2]
- for (QChar ch : funcReturningQString())
- process(ch); // OK, the returned object is kept alive for the loop's duration
-//! [as-const-2]
-
-//! [as-const-3]
- for (QChar ch : qAsConst(funcReturningQString()))
- process(ch); // ERROR: ch is copied from deleted memory
-//! [as-const-3]
-
-//! [as-const-4]
- for (QChar ch : qAsConst(funcReturningQString()))
- process(ch); // ERROR: ch is copied from deleted memory
-//! [as-const-4]
-
-//! [qdecloverride]
- // generate error if this doesn't actually override anything:
- virtual void MyWidget::paintEvent(QPaintEvent*) override;
-//! [qdecloverride]
-
-//! [qdeclfinal-1]
- // more-derived classes no longer permitted to override this:
- virtual void MyWidget::paintEvent(QPaintEvent*) final;
-//! [qdeclfinal-1]
+ //! [int-value_or]
+ auto value = qEnvironmentVariableIntegerValue(varName).value_or(0);
+ //! [int-value_or]
+
+ //! [int-eq0]
+ bool equals_zero = qEnvironmentVariableIntegerValue(varName) == 0;
+ //! [int-eq0]
+
+ //! [is-null]
+ bool is_not_null = !qgetenv(varName).isNull();
+ //! [is-null]
+}
+
+QString funcReturningQString()
+{
+ return "Hello, World!";
+}
+void process(const QChar &ch) { }
+
+void qchar_examples()
+{
+ {
+ //! [as-const-0]
+ QString s = "...";
+ for (QChar ch : s) // detaches 's' (performs a deep-copy if 's' was shared)
+ process(ch);
+ for (QChar ch : qAsConst(s)) // ok, no detach attempt
+ process(ch);
+ //! [as-const-0]
+ }
+
+ //! [as-const-1]
+ const QString s = "...";
+ for (QChar ch : s) // ok, no detach attempt on const objects
+ process(ch);
+ //! [as-const-1]
+
+ //! [as-const-2]
+ for (QChar ch : funcReturningQString())
+ process(ch); // OK, the returned object is kept alive for the loop's duration
+ //! [as-const-2]
+
+#if MAKE_ERRORS
+ //! [as-const-3]
+ for (QChar ch : qAsConst(funcReturningQString()))
+ process(ch); // ERROR: ch is copied from deleted memory
+ //! [as-const-3]
+
+ //! [as-const-4]
+ for (QChar ch : qAsConst(funcReturningQString()))
+ process(ch); // ERROR: ch is copied from deleted memory
+ //! [as-const-4]
+#endif
+}
+
+class ExampleClass
+{
+protected:
+#if MAKE_ERRORS
+ //! [qdecloverride]
+ // generate error if this doesn't actually override anything:
+ virtual void override_func() override;
+ //! [qdecloverride]
+#endif
+
+ //! [qdeclfinal-1]
+ // more-derived classes no longer permitted to override this:
+ virtual void final_func() final;
+ //! [qdeclfinal-1]
+};
//! [qdeclfinal-2]
- class QRect final { // cannot be derived from
+ class SomeClass final { // cannot be derived from
// ...
};
//! [qdeclfinal-2]
diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qlogging.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qlogging.cpp
index 4a31a2e6617..d035606629c 100644
--- a/src/corelib/doc/snippets/code/src_corelib_global_qlogging.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_global_qlogging.cpp
@@ -1,6 +1,7 @@
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
+#if MESSAGE
//! [0]
QT_MESSAGE_PATTERN="[%{time yyyyMMdd h:mm:ss.zzz ttt} %{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{file}:%{line} - %{message}"
//! [0]
+#endif
diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qnumeric.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qnumeric.cpp
index d88675d8f15..94ee3abf4fa 100644
--- a/src/corelib/doc/snippets/code/src_corelib_global_qnumeric.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_global_qnumeric.cpp
@@ -1,9 +1,14 @@
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [0]
- if (qFloatDistance(a, b) < (1 << 7)) { // The last 7 bits are not
- // significant
- // precise enough
- }
-//! [0]
+#include <QtNumeric>
+
+void example(float a, float b)
+{
+ //! [0]
+ if (qFloatDistance(a, b) < (1 << 7)) { // The last 7 bits are not
+ // significant
+ // precise enough
+ }
+ //! [0]
+}
diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qoperatingsystemversion.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qoperatingsystemversion.cpp
index d86d40bc981..ab49a634527 100644
--- a/src/corelib/doc/snippets/code/src_corelib_global_qoperatingsystemversion.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_global_qoperatingsystemversion.cpp
@@ -1,14 +1,19 @@
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [0]
- QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::IOS, 9)
-//! [0]
+#include <QOperatingSystemVersion>
-//! [1]
- auto current = QOperatingSystemVersion::current();
- if (current >= QOperatingSystemVersion::OSXYosemite ||
- current >= QOperatingSystemVersion(QOperatingSystemVersion::IOS, 8)) {
- // returns true on macOS >= 10.10 and iOS >= 8.0, but false on macOS < 10.10 and iOS < 8.0
- }
-//! [1]
+void example()
+{
+ //! [0]
+ bool ios_higher_then_9 = QOperatingSystemVersion::current() >= QOperatingSystemVersion(QOperatingSystemVersion::IOS, 9);
+ //! [0]
+
+ //! [1]
+ auto current = QOperatingSystemVersion::current();
+ if (current >= QOperatingSystemVersion::OSXYosemite ||
+ current >= QOperatingSystemVersion(QOperatingSystemVersion::IOS, 8)) {
+ // returns true on macOS >= 10.10 and iOS >= 8.0, but false on macOS < 10.10 and iOS < 8.0
+ }
+ //! [1]
+}
diff --git a/src/corelib/doc/snippets/code/src_corelib_global_qrandom.cpp b/src/corelib/doc/snippets/code/src_corelib_global_qrandom.cpp
index 8be3f91120f..c3112d11768 100644
--- a/src/corelib/doc/snippets/code/src_corelib_global_qrandom.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_global_qrandom.cpp
@@ -2,83 +2,117 @@
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [0]
- quint32 value = QRandomGenerator::global()->generate();
-//! [0]
-
-//! [1]
- QRandomGenerator prng1(1234), prng2(1234);
- Q_ASSERT(prng1.generate() == prng2.generate());
- Q_ASSERT(prng1.generate64() == prng2.generate64());
-//! [1]
-
-//! [2]
- int x = QRandomGenerator::global()->generate();
- int y = QRandomGenerator::global()->generate();
- int w = QRandomGenerator::global()->bounded(16384);
- int h = QRandomGenerator::global()->bounded(16384);
-//! [2]
-
-//! [3]
- std::uniform_real_distribution dist(1, 2.5);
- return dist(*QRandomGenerator::global());
-//! [3]
-
-//! [4]
- std::seed_seq sseq(seedBuffer, seedBuffer + len);
- QRandomGenerator generator(sseq);
-//! [4]
-
-//! [5]
- std::seed_seq sseq(begin, end);
- QRandomGenerator generator(sseq);
-//! [5]
-
-//! [6]
- while (z--)
- generator.generate();
-//! [6]
-
-//! [7]
- std::generate(begin, end, [this]() { return generate(); });
-//! [7]
-
-//! [8]
- std::generate(begin, end, []() { return QRandomGenerator::global()->generate64(); });
-//! [8]
-
-//! [9]
- QList<quint32> list;
- list.resize(16);
- QRandomGenerator::global()->fillRange(list.data(), list.size());
-//! [9]
-
-//! [10]
- quint32 array[2];
- QRandomGenerator::global()->fillRange(array);
-//! [10]
-
-//! [11]
- QRandomGenerator64 rd;
- return std::generate_canonical<qreal, std::numeric_limits<qreal>::digits>(rd);
-//! [11]
-
-//! [12]
- return generateDouble() * highest;
-//! [12]
-
-//! [13]
- quint32 v = QRandomGenerator::global()->bounded(256);
-//! [13]
-
-//! [14]
- quint32 v = QRandomGenerator::global()->bounded(1000, 2000);
-//! [14]
-
-//! [15]
- return QColor::fromRgb(QRandomGenerator::global()->generate());
-//! [15]
-
-//! [16]
- qint64 value = QRandomGenerator64::global()->generate() & std::numeric_limits<qint64>::max();
-//! [16]
+#include <QRandomGenerator>
+#include <QList>
+
+double snippets_1_2_3()
+{
+ //! [0]
+ quint32 value = QRandomGenerator::global()->generate();
+ //! [0]
+
+ //! [1]
+ QRandomGenerator prng1(1234), prng2(1234);
+ Q_ASSERT(prng1.generate() == prng2.generate());
+ Q_ASSERT(prng1.generate64() == prng2.generate64());
+ //! [1]
+
+ //! [2]
+ int x = QRandomGenerator::global()->generate();
+ int y = QRandomGenerator::global()->generate();
+ int w = QRandomGenerator::global()->bounded(16384);
+ int h = QRandomGenerator::global()->bounded(16384);
+ //! [2]
+
+ //! [3]
+ std::uniform_real_distribution<> dist(1, 2.5);
+ return dist(*QRandomGenerator::global());
+ //! [3]
+}
+class Generator : public QRandomGenerator
+{
+ public:
+ qreal snippets_4_to_11(int z, quint32 *begin, quint32 *end, const quint32 *seedBuffer, size_t len);
+};
+
+qreal Generator::snippets_4_to_11(int z, quint32 *begin, quint32 *end, const quint32 *seedBuffer, size_t len)
+{
+ {
+ //! [4]
+ std::seed_seq sseq(seedBuffer, seedBuffer + len);
+ QRandomGenerator generator(sseq);
+ //! [4]
+ }
+
+ //! [5]
+ std::seed_seq sseq(begin, end);
+ QRandomGenerator generator(sseq);
+ //! [5]
+
+ //! [6]
+ while (z--)
+ generator.generate();
+ //! [6]
+
+ //! [7]
+ std::generate(begin, end, [this]() { return generate(); });
+ //! [7]
+
+ //! [8]
+ std::generate(begin, end, []() { return QRandomGenerator::global()->generate64(); });
+ //! [8]
+
+ //! [9]
+ QList<quint32> list;
+ list.resize(16);
+ QRandomGenerator::global()->fillRange(list.data(), list.size());
+ //! [9]
+
+ //! [10]
+ quint32 array[2];
+ QRandomGenerator::global()->fillRange(array);
+ //! [10]
+
+ //! [11]
+ QRandomGenerator64 rd;
+ return std::generate_canonical<qreal, std::numeric_limits<qreal>::digits>(rd);
+ //! [11]
+}
+
+double generateDouble()
+{
+ return 0.0;
+}
+
+double generateDoubleWithHighest(double highest)
+{
+ //! [12]
+ return generateDouble() * highest;
+ //! [12]
+}
+
+#include <QColor>
+
+QColor snippets_13_to_15()
+{
+ {
+ //! [13]
+ quint32 v = QRandomGenerator::global()->bounded(256);
+ //! [13]
+ }
+
+ //! [14]
+ quint32 v = QRandomGenerator::global()->bounded(1000, 2000);
+ //! [14]
+
+ //! [15]
+ return QColor::fromRgb(QRandomGenerator::global()->generate());
+ //! [15]
+}
+
+void snippet_16()
+{
+ //! [16]
+ qint64 value = QRandomGenerator64::global()->generate() & std::numeric_limits<qint64>::max();
+ //! [16]
+}
diff --git a/src/corelib/doc/snippets/eventfilters/CMakeLists.txt b/src/corelib/doc/snippets/eventfilters/CMakeLists.txt
index ea381e425a5..7da83cbdf6e 100644
--- a/src/corelib/doc/snippets/eventfilters/CMakeLists.txt
+++ b/src/corelib/doc/snippets/eventfilters/CMakeLists.txt
@@ -1,17 +1,19 @@
-add_library(snippets_eventfilters OBJECT)
+add_library(corelib_snippets_eventfilters OBJECT)
-target_link_libraries(snippets_eventfilters PRIVATE
+set_target_properties(corelib_snippets_eventfilters PROPERTIES COMPILE_OPTIONS "-w")
+
+target_link_libraries(corelib_snippets_eventfilters PRIVATE
Qt::Core
)
-qt_internal_extend_target(snippets_eventfilters CONDITION QT_FEATURE_widgets
+qt_internal_extend_target(corelib_snippets_eventfilters CONDITION QT_FEATURE_widgets
LIBRARIES
Qt::Widgets
SOURCE
main.cpp
)
-qt_internal_extend_target(snippets_eventfilters CONDITION QT_FEATURE_gui
+qt_internal_extend_target(corelib_snippets_eventfilters CONDITION QT_FEATURE_gui
LIBRARIES
Qt::Gui
SOURCES
diff --git a/src/corelib/doc/snippets/qmetaobject-invokable/CMakeLists.txt b/src/corelib/doc/snippets/qmetaobject-invokable/CMakeLists.txt
index 76bb79951a3..972bf43d9b1 100644
--- a/src/corelib/doc/snippets/qmetaobject-invokable/CMakeLists.txt
+++ b/src/corelib/doc/snippets/qmetaobject-invokable/CMakeLists.txt
@@ -2,13 +2,15 @@ if(NOT QT_FEATURE_widgets)
return()
endif()
-add_library(snippets_qmetaobject-invokable OBJECT)
+add_library(corelib_snippets_qmetaobject-invokable OBJECT)
-target_link_libraries(snippets_qmetaobject-invokable PRIVATE
+set_target_properties(corelib_snippets_qmetaobject-invokable PROPERTIES COMPILE_OPTIONS "-w")
+
+target_link_libraries(corelib_snippets_qmetaobject-invokable PRIVATE
Qt::Core
)
-qt_internal_extend_target(snippets_qmetaobject-invokable CONDITION QT_FEATURE_widgets
+qt_internal_extend_target(corelib_snippets_qmetaobject-invokable CONDITION QT_FEATURE_widgets
LIBRARIES
Qt::Widgets
SOURCES
diff --git a/src/corelib/doc/snippets/qmetaobject-revision/CMakeLists.txt b/src/corelib/doc/snippets/qmetaobject-revision/CMakeLists.txt
index 0cadf9380b1..369b2e15315 100644
--- a/src/corelib/doc/snippets/qmetaobject-revision/CMakeLists.txt
+++ b/src/corelib/doc/snippets/qmetaobject-revision/CMakeLists.txt
@@ -2,13 +2,15 @@ if(NOT QT_FEATURE_widgets)
return()
endif()
-add_library(snippets_qmetaobject-revision OBJECT)
+add_library(corelib_snippets_qmetaobject-revision OBJECT)
-target_link_libraries(snippets_qmetaobject-revision PRIVATE
+set_target_properties(corelib_snippets_qmetaobject-revision PROPERTIES COMPILE_OPTIONS "-w")
+
+target_link_libraries(corelib_snippets_qmetaobject-revision PRIVATE
Qt::Core
)
-qt_internal_extend_target(snippets_qmetaobject-revision CONDITION QT_FEATURE_widgets
+qt_internal_extend_target(corelib_snippets_qmetaobject-revision CONDITION QT_FEATURE_widgets
LIBRARIES
Qt::Widgets
SOURCES
diff --git a/src/corelib/doc/snippets/qprocess/CMakeLists.txt b/src/corelib/doc/snippets/qprocess/CMakeLists.txt
index d410d479f7f..d00e051ed9b 100644
--- a/src/corelib/doc/snippets/qprocess/CMakeLists.txt
+++ b/src/corelib/doc/snippets/qprocess/CMakeLists.txt
@@ -1,10 +1,12 @@
set(CMAKE_UNITY_BUILD OFF)
-add_library(snippets_qprocess OBJECT
+add_library(corelib_snippets_qprocess OBJECT
qprocess-createprocessargumentsmodifier.cpp
qprocess-simpleexecution.cpp
)
-target_link_libraries(snippets_qprocess PRIVATE
+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/snippets/qsignalmapper/CMakeLists.txt b/src/corelib/doc/snippets/qsignalmapper/CMakeLists.txt
deleted file mode 100644
index 086ddbf9c5e..00000000000
--- a/src/corelib/doc/snippets/qsignalmapper/CMakeLists.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-if(NOT TARGET Qt::Widgets)
- return()
-endif()
-
-add_library(snippets_qsignalmapper OBJECT
- buttonwidget.cpp
-)
-
-add_compile_definitions(EXAMPLE_ONE)
-
-target_link_libraries(snippets_qsignalmapper PRIVATE
- Qt::Core
-)
-
-qt_internal_extend_target(snippets_qsignalmapper CONDITION QT_FEATURE_widgets
- LIBRARIES
- Qt::Widgets
-)
diff --git a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp
index 1f9e53f1385..cdbf83a977d 100644
--- a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp
+++ b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp
@@ -5,39 +5,40 @@
#include <QtWidgets>
-#ifdef EXAMPLE_ONE
-//! [0]
-ButtonWidget::ButtonWidget(const QStringList &texts, QWidget *parent)
- : QWidget(parent)
-{
- signalMapper = new QSignalMapper(this);
+ //! [OpenCtor]
+ ButtonWidget::ButtonWidget(const QStringList &texts, QWidget *parent)
+ : QWidget(parent)
+ {
+ //! [OpenCtor]
+ {
+ //![OldNotation]
+ signalMapper = new QSignalMapper(this);
- QGridLayout *gridLayout = new QGridLayout(this);
- for (int i = 0; i < texts.size(); ++i) {
- QPushButton *button = new QPushButton(texts[i]);
- connect(button, &QPushButton::clicked, signalMapper, qOverload<>(&QSignalMapper::map));
-//! [0] //! [1]
- signalMapper->setMapping(button, texts[i]);
- gridLayout->addWidget(button, i / 3, i % 3);
+ QGridLayout *gridLayout = new QGridLayout(this);
+ for (int i = 0; i < texts.size(); ++i) {
+ QPushButton *button = new QPushButton(texts[i]);
+ connect(button, &QPushButton::clicked, signalMapper, qOverload<>(&QSignalMapper::map));
+ signalMapper->setMapping(button, texts[i]);
+ gridLayout->addWidget(button, i / 3, i % 3);
+ }
+
+ connect(signalMapper, &QSignalMapper::mappedString,
+ this, &ButtonWidget::clicked);
+ //![OldNotation]
+ }
+
+ {
+ //![ModernNotation]
+ QGridLayout *gridLayout = new QGridLayout(this);
+ for (int i = 0; i < texts.size(); ++i) {
+ QString text = texts[i];
+ QPushButton *button = new QPushButton(text);
+ connect(button, &QPushButton::clicked, [this, text] { clicked(text); });
+ gridLayout->addWidget(button, i / 3, i % 3);
+ }
+ //![ModernNotation]
}
- connect(signalMapper, &QSignalMapper::mappedString,
-//! [1] //! [2]
- this, &ButtonWidget::clicked);
-}
-//! [2]
-#else
-//! [3]
-ButtonWidget::ButtonWidget(const QStringList &texts, QWidget *parent)
- : QWidget(parent)
-{
- QGridLayout *gridLayout = new QGridLayout(this);
- for (int i = 0; i < texts.size(); ++i) {
- QString text = texts[i];
- QPushButton *button = new QPushButton(text);
- connect(button, &QPushButton::clicked, [this, text] { clicked(text); });
- gridLayout->addWidget(button, i / 3, i % 3);
+ //! [CloseBrackets]
}
-}
-//! [3]
-#endif
+ //! [CloseBrackets]
diff --git a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h
index 537c21c9141..cd75628dc2b 100644
--- a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h
+++ b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.h
@@ -4,10 +4,8 @@
#ifndef BUTTONWIDGET_H
#define BUTTONWIDGET_H
-#include <QWidget>
+#include <QtWidgets>
-class QSignalMapper;
-class QString;
//! [0]
class ButtonWidget : public QWidget
diff --git a/src/corelib/doc/src/animation.qdoc b/src/corelib/doc/src/animation.qdoc
index d2e182f4806..ba5976f11eb 100644
--- a/src/corelib/doc/src/animation.qdoc
+++ b/src/corelib/doc/src/animation.qdoc
@@ -91,7 +91,12 @@
The following example demonstrates how you can animate a QPushButton
widget:
- \snippet code/src_corelib_animation_qpropertyanimation.cpp 0
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp includes
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp class_decl
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp ctor_impl
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp first_example
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp ctor_close
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp main
The example animates the \c pos Qt property of a QPushButton, to move
it from the top--left corner of the screen to the end position (250, 250),
@@ -174,7 +179,9 @@
path.
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp ctor_impl
\snippet code/src_corelib_animation_qpropertyanimation.cpp easing-curve
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp ctor_close
In this example, the animation follows a curve that makes the
\c button bounce like a ball. QEasingCurve offers a large collection of curves
@@ -199,13 +206,17 @@
The two following examples demonstrate the use of both
QSequentialAnimationGroup and QParallelAnimationGroup:
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp ctor_impl
\snippet code/src_corelib_animation_qpropertyanimation.cpp animation-group1
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp ctor_close
A parallel group plays more than one animation at the same time.
Its \l{QAbstractAnimation::}{start()} function starts all
animations that are part of the group.
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp ctor_impl
\snippet code/src_corelib_animation_qpropertyanimation.cpp animation-group2
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp ctor_close
As the name suggests, a QSequentialAnimationGroup plays
its animations in sequence. It starts the next animation in
@@ -225,7 +236,12 @@
independent QPropertyAnimation has the QApplication instance as its
parent:
- \snippet code/src_corelib_animation_qpropertyanimation.cpp 0
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp includes
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp class_decl
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp ctor_impl
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp first_example
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp ctor_close
+ \snippet code/src_corelib_animation_qpropertyanimation.cpp main
\note You can also control the animation's lifespan by choosing a
\l{QAbstractAnimation::DeletionPolicy}{delete policy} while starting it.
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/global/qassert.cpp b/src/corelib/global/qassert.cpp
index 208619fd5cc..4da8a0cb037 100644
--- a/src/corelib/global/qassert.cpp
+++ b/src/corelib/global/qassert.cpp
@@ -63,7 +63,9 @@ Q_NORETURN void qAbort()
Example:
- \snippet code/src_corelib_global_qglobal.cpp 17
+ \snippet code/src_corelib_global_qglobal.cpp 17&19_include_open
+ \snippet code/src_corelib_global_qglobal.cpp 17assert
+ \snippet code/src_corelib_global_qglobal.cpp 17&19_return_close
If \c b is zero, the Q_ASSERT statement will output the following
message using the qFatal() function:
@@ -86,7 +88,9 @@ Q_NORETURN void qAbort()
Example:
- \snippet code/src_corelib_global_qglobal.cpp 19
+ \snippet code/src_corelib_global_qglobal.cpp 17&19_include_open
+ \snippet code/src_corelib_global_qglobal.cpp 19assert
+ \snippet code/src_corelib_global_qglobal.cpp 17&19_return_close
If \c b is zero, the Q_ASSERT_X statement will output the following
message using the qFatal() function:
diff --git a/src/corelib/global/qforeach.qdoc b/src/corelib/global/qforeach.qdoc
index e6abf0e29c8..bec01152c04 100644
--- a/src/corelib/global/qforeach.qdoc
+++ b/src/corelib/global/qforeach.qdoc
@@ -50,7 +50,7 @@
If you're worried about namespace pollution, you can disable this
macro by adding the following line to your \c .pro file:
- \snippet code/src_corelib_global_qglobal.cpp 33
+ \snippet code/src_corelib_global_qglobal.cpp 32
\note Since Qt 5.7, the use of this macro is discouraged.
Use C++11 range-based \c for, possibly with \c {std::as_const()},
diff --git a/src/corelib/io/qdebug.cpp b/src/corelib/io/qdebug.cpp
index 645f27798c4..5d6b5e06be6 100644
--- a/src/corelib/io/qdebug.cpp
+++ b/src/corelib/io/qdebug.cpp
@@ -200,7 +200,7 @@ template <typename Char>
static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, size_t length, bool isUnicode = true)
{
QChar quote(u'"');
- d->write(&quote, 1);
+ d->write(quote);
bool lastWasHexEscape = false;
const Char *end = begin + length;
@@ -227,8 +227,7 @@ static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, si
continue;
}
} else if (isPrintable(*p) && *p != '\\' && *p != '"') {
- QChar c = QLatin1Char(*p);
- d->write(&c, 1);
+ d->write(char16_t{uchar(*p)});
continue;
}
@@ -302,7 +301,7 @@ static inline void putEscapedString(QTextStreamPrivate *d, const Char *begin, si
d->write(reinterpret_cast<QChar *>(buf), buflen);
}
- d->write(&quote, 1);
+ d->write(quote);
}
/*!
@@ -332,9 +331,14 @@ void QDebug::putByteArray(const char *begin, size_t length, Latin1Content conten
if (stream->noQuotes) {
// no quotes, write the string directly too (no pretty-printing)
// this respects the QTextStream state, though
- QString string = content == ContainsLatin1 ? QString::fromLatin1(begin, qsizetype(length))
- : QString::fromUtf8(begin, qsizetype(length));
- stream->ts.d_ptr->putString(string);
+ switch (content) {
+ case Latin1Content::ContainsLatin1:
+ stream->ts.d_ptr->putString(QLatin1StringView{begin, qsizetype(length)});
+ break;
+ case Latin1Content::ContainsBinary:
+ stream->ts.d_ptr->putString(QUtf8StringView{begin, qsizetype(length)});
+ break;
+ }
} else {
// we'll reset the QTextStream formatting mechanisms, so save the state
QDebugStateSaver saver(*this);
diff --git a/src/corelib/io/qdirlisting.cpp b/src/corelib/io/qdirlisting.cpp
index c626033dcdb..1fec92a01e2 100644
--- a/src/corelib/io/qdirlisting.cpp
+++ b/src/corelib/io/qdirlisting.cpp
@@ -510,16 +510,14 @@ bool QDirListingPrivate::matchesFilters(QDirEntryInfo &entryInfo) const
if (!iteratorFlags.testAnyFlag(F::IncludeHidden) && entryInfo.isHidden())
return false;
- if (entryInfo.isSymLink()) {
- // With ResolveSymlinks, we look at the type of the link's target,
- // and exclude broken symlinks (where the target doesn't exist).
- if (iteratorFlags.testAnyFlag(F::ResolveSymlinks)) {
- if (!entryInfo.exists())
- return false;
- } else if (iteratorFlags.testAnyFlags(F::FilesOnly)
- || iteratorFlags.testAnyFlags(F::DirsOnly)) {
- return false; // symlink is not a file or dir
- }
+ // With ResolveSymlinks, we look at the type of the link's target,
+ // and exclude broken symlinks (where the target doesn't exist).
+ if (iteratorFlags.testAnyFlag(F::ResolveSymlinks)) {
+ if (entryInfo.isSymLink() && !entryInfo.exists())
+ return false;
+ } else if ((iteratorFlags.testAnyFlags(F::FilesOnly)
+ || iteratorFlags.testAnyFlags(F::DirsOnly)) && entryInfo.isSymLink()) {
+ return false; // symlink is not a file or dir
}
if (iteratorFlags.testAnyFlag(F::ExcludeOther)
diff --git a/src/corelib/io/qfilesystemengine.cpp b/src/corelib/io/qfilesystemengine.cpp
index c69ac381020..03da2331e05 100644
--- a/src/corelib/io/qfilesystemengine.cpp
+++ b/src/corelib/io/qfilesystemengine.cpp
@@ -1,5 +1,6 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+// Qt-Security score:critical reason:data-parser
#include "qfilesystemengine_p.h"
#include <QtCore/qdir.h>
diff --git a/src/corelib/io/qfilesystemengine_mac.mm b/src/corelib/io/qfilesystemengine_mac.mm
index a0dc83321e4..08fe2afc81c 100644
--- a/src/corelib/io/qfilesystemengine_mac.mm
+++ b/src/corelib/io/qfilesystemengine_mac.mm
@@ -1,5 +1,6 @@
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+// Qt-Security score:significant reason:default
#include "qplatformdefs.h"
#include "qfilesystemengine_p.h"
diff --git a/src/corelib/io/qfilesystemengine_p.h b/src/corelib/io/qfilesystemengine_p.h
index 773c1d34f87..ee70ccc1e1b 100644
--- a/src/corelib/io/qfilesystemengine_p.h
+++ b/src/corelib/io/qfilesystemengine_p.h
@@ -1,5 +1,6 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+// Qt-Security score:critical reason:data-parser
#ifndef QFILESYSTEMENGINE_P_H
#define QFILESYSTEMENGINE_P_H
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index 5a0be1d895e..98d6f4b003f 100644
--- a/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/src/corelib/io/qfilesystemengine_unix.cpp
@@ -2,6 +2,7 @@
// Copyright (C) 2016 The Qt Company Ltd.
// Copyright (C) 2013 Samuel Gaist <[email protected]>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+// Qt-Security score:critical reason:data-parser
#include "qplatformdefs.h"
#include "qfilesystemengine_p.h"
diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp
index f8b5806cb35..1ad90f16996 100644
--- a/src/corelib/io/qfilesystemengine_win.cpp
+++ b/src/corelib/io/qfilesystemengine_win.cpp
@@ -1,5 +1,6 @@
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+// Qt-Security score:critical reason:data-parser
#include "qfilesystemengine_p.h"
#include "qoperatingsystemversion.h"
diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp
index 1b711ba16bd..55d9cea7c6c 100644
--- a/src/corelib/kernel/qcoreapplication.cpp
+++ b/src/corelib/kernel/qcoreapplication.cpp
@@ -1618,6 +1618,17 @@ QCoreApplicationPrivate::QPostEventListLocker QCoreApplicationPrivate::lockThrea
details. Events with equal \a priority will be processed in the
order posted.
+ \note QObject::deleteLater() schedules the object for deferred
+ deletion, which is typically handled by the receiver's event
+ loop. If no event loop is running in the thread, the deletion
+ will be performed when the thread finishes. A common and safe
+ pattern is to connect the thread's finished() signal to the
+ object's deleteLater() slot:
+
+ \code
+ QObject::connect(thread, &QThread::finished, worker, &QObject::deleteLater);
+ \endcode
+
\threadsafe
\sa sendEvent(), notify(), sendPostedEvents(), Qt::EventPriority
diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp
index de5f27f9619..7f000830e6a 100644
--- a/src/corelib/kernel/qmetaobject.cpp
+++ b/src/corelib/kernel/qmetaobject.cpp
@@ -808,8 +808,7 @@ static int indexOfMethod_helper(const QMetaObject *m, const char *method)
int QMetaObject::indexOfMethod(const char *method) const
{
- const QMetaObject *m = this;
- int i = indexOfMethod_helper(m, method);
+ int i = indexOfMethod_helper(this, method);
INDEXOF_COMPAT(Method, method);
return i;
}
@@ -881,8 +880,7 @@ static int indexOfSignal_helper(const QMetaObject *m, const char *signal)
int QMetaObject::indexOfSignal(const char *signal) const
{
- const QMetaObject *m = this;
- int i = indexOfSignal_helper(m, signal);
+ int i = indexOfSignal_helper(this, signal);
INDEXOF_COMPAT(Signal, signal);
return i;
}
@@ -938,8 +936,7 @@ static int indexOfSlot_helper(const QMetaObject *m, const char *slot)
int QMetaObject::indexOfSlot(const char *slot) const
{
- const QMetaObject *m = this;
- int i = indexOfSlot_helper(m, slot);
+ int i = indexOfSlot_helper(this, slot);
INDEXOF_COMPAT(Slot, slot);
return i;
}
@@ -1733,16 +1730,8 @@ bool QMetaObject::invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *
"queued connections");
return false;
}
- auto event = std::make_unique<QMetaCallEvent>(std::move(slot), nullptr, -1, parameterCount);
- void **args = event->args();
- QMetaType *types = event->types();
-
- for (int i = 1; i < parameterCount; ++i) {
- types[i] = QMetaType(metaTypes[i]);
- args[i] = types[i].create(argv[i]);
- }
-
- QCoreApplication::postEvent(object, event.release());
+ QCoreApplication::postEvent(object, new QQueuedMetaCallEvent(std::move(slot), nullptr, -1,
+ parameterCount, metaTypes, params));
} else if (type == Qt::BlockingQueuedConnection) {
#if QT_CONFIG(thread)
if (receiverInSameThread)
@@ -2889,31 +2878,27 @@ auto QMetaMethodInvoker::invokeImpl(QMetaMethod self, void *target,
return InvokeFailReason::CouldNotQueueParameter;
}
- auto event = std::make_unique<QMetaCallEvent>(idx_offset, idx_relative, callFunction, nullptr, -1, paramCount);
- QMetaType *types = event->types();
- void **args = event->args();
-
+ QVarLengthArray<const QtPrivate::QMetaTypeInterface *> argTypes;
+ argTypes.emplace_back(nullptr); // return type
// fill in the meta types first
for (int i = 1; i < paramCount; ++i) {
- types[i] = QMetaType(methodMetaTypes[i - 1]);
- if (!types[i].iface() && (!MetaTypesAreOptional || metaTypes))
- types[i] = QMetaType(metaTypes[i]);
- if (!types[i].iface())
- types[i] = priv->parameterMetaType(i - 1);
- if (!types[i].iface() && typeNames[i])
- types[i] = QMetaType::fromName(typeNames[i]);
- if (!types[i].iface()) {
+ QMetaType type = QMetaType(methodMetaTypes[i - 1]);
+ if (!type.iface() && (!MetaTypesAreOptional || metaTypes))
+ type = QMetaType(metaTypes[i]);
+ if (!type.iface())
+ type = priv->parameterMetaType(i - 1);
+ if (!type.iface() && typeNames[i])
+ type = QMetaType::fromName(typeNames[i]);
+ if (!type.iface()) {
qWarning("QMetaMethod::invoke: Unable to handle unregistered datatype '%s'",
typeNames[i]);
return InvokeFailReason(int(InvokeFailReason::CouldNotQueueParameter) - i);
}
+ argTypes.emplace_back(type.iface());
}
- // now create copies of our parameters using those meta types
- for (int i = 1; i < paramCount; ++i)
- args[i] = types[i].create(parameters[i]);
-
- QCoreApplication::postEvent(object, event.release());
+ QCoreApplication::postEvent(object, new QQueuedMetaCallEvent(idx_offset, idx_relative, callFunction, nullptr,
+ -1, paramCount, argTypes.data(), parameters));
} else { // blocking queued connection
#if QT_CONFIG(thread)
if (receiverInSameThread()) {
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 888c71f5a49..790ccc29339 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -599,14 +599,19 @@ QMetaCallEvent::QMetaCallEvent(QtPrivate::SlotObjUniquePtr slotO,
/*!
\internal
*/
+QMetaCallEvent::QMetaCallEvent(const QObject *sender, int signalId, Data &&data)
+ : QAbstractMetaCallEvent(sender, signalId),
+ d(std::move(data)),
+ prealloc_()
+{
+}
+
+/*!
+ \internal
+ */
QMetaCallEvent::~QMetaCallEvent()
{
if (d.nargs_) {
- QMetaType *t = types();
- for (int i = 0; i < d.nargs_; ++i) {
- if (t[i].isValid() && d.args_[i])
- t[i].destroy(d.args_[i]);
- }
if (reinterpret_cast<void *>(d.args_) != reinterpret_cast<void *>(prealloc_))
free(d.args_);
}
@@ -628,6 +633,115 @@ void QMetaCallEvent::placeMetaCall(QObject *object)
}
/*!
+ \internal
+
+ Constructs a QQueuedMetaCallEvent by copying the argument values using their meta-types.
+ */
+QQueuedMetaCallEvent::QQueuedMetaCallEvent(ushort method_offset, ushort method_relative,
+ QObjectPrivate::StaticMetaCallFunction callFunction,
+ const QObject *sender, int signalId, int argCount,
+ const QtPrivate::QMetaTypeInterface * const *argTypes,
+ const void * const *argValues)
+ : QMetaCallEvent(sender, signalId, {nullptr, nullptr, callFunction, argCount,
+ method_offset, method_relative})
+{
+ allocArgs();
+ copyArgValues(argCount, argTypes, argValues);
+}
+
+/*!
+ \internal
+
+ Constructs a QQueuedMetaCallEvent by copying the argument values using their meta-types.
+ */
+QQueuedMetaCallEvent::QQueuedMetaCallEvent(QtPrivate::QSlotObjectBase *slotObj,
+ const QObject *sender, int signalId, int argCount,
+ const QtPrivate::QMetaTypeInterface * const *argTypes,
+ const void * const *argValues)
+ : QMetaCallEvent(sender, signalId, {QtPrivate::SlotObjUniquePtr(slotObj), nullptr, nullptr, argCount,
+ 0, ushort(-1)})
+{
+ if (d.slotObj_)
+ d.slotObj_->ref();
+ allocArgs();
+ copyArgValues(argCount, argTypes, argValues);
+}
+
+/*!
+ \internal
+
+ Constructs a QQueuedMetaCallEvent by copying the argument values using their meta-types.
+ */
+QQueuedMetaCallEvent::QQueuedMetaCallEvent(QtPrivate::SlotObjUniquePtr slotObj,
+ const QObject *sender, int signalId, int argCount,
+ const QtPrivate::QMetaTypeInterface * const *argTypes,
+ const void * const *argValues)
+ : QMetaCallEvent(sender, signalId, {std::move(slotObj), nullptr, nullptr, argCount,
+ 0, ushort(-1)})
+{
+ allocArgs();
+ copyArgValues(argCount, argTypes, argValues);
+}
+
+/*!
+ \internal
+ */
+QQueuedMetaCallEvent::~QQueuedMetaCallEvent()
+{
+ const QMetaType *t = types();
+ int inplaceIndex = 0;
+ for (int i = 0; i < d.nargs_; ++i) {
+ if (t[i].isValid() && d.args_[i]) {
+ if (typeFitsInPlace(t[i]) && inplaceIndex < InplaceValuesCapacity) {
+ // Only destruct
+ void *where = &valuesPrealloc_[inplaceIndex++].storage;
+ t[i].destruct(where);
+ } else {
+ // Destruct and deallocate
+ t[i].destroy(d.args_[i]);
+ }
+ }
+ }
+}
+
+/*!
+ \internal
+ */
+inline void QQueuedMetaCallEvent::copyArgValues(int argCount, const QtPrivate::QMetaTypeInterface * const *argTypes,
+ const void * const *argValues)
+{
+ void **args = d.args_;
+ QMetaType *types = this->types();
+ int inplaceIndex = 0;
+
+ types[0] = QMetaType(); // return type
+ args[0] = nullptr; // return value pointer
+ // no return value
+
+ for (int n = 1; n < argCount; ++n) {
+ types[n] = QMetaType(argTypes[n]);
+ if (typeFitsInPlace(types[n]) && inplaceIndex < InplaceValuesCapacity) {
+ // Copy-construct in place
+ void *where = &valuesPrealloc_[inplaceIndex++].storage;
+ types[n].construct(where, argValues[n]);
+ args[n] = where;
+ } else {
+ // Allocate and copy-construct
+ args[n] = types[n].create(argValues[n]);
+ }
+ }
+}
+
+/*!
+ \internal
+ */
+inline bool QQueuedMetaCallEvent::typeFitsInPlace(const QMetaType type)
+{
+ return (q20::cmp_less_equal(type.sizeOf(), sizeof(ArgValueStorage)) &&
+ q20::cmp_less_equal(type.alignOf(), alignof(ArgValueStorage)));
+}
+
+/*!
\class QSignalBlocker
\brief Exception-safe wrapper around QObject::blockSignals().
\since 5.3
@@ -2406,6 +2520,14 @@ void QObject::removeEventFilter(QObject *obj)
thread with no running event loop, the object will be destroyed when the
thread finishes.
+ A common pattern when using a worker \c QObject in a \c QThread
+ is to connect the thread's \c finished() signal to the worker's
+ \c deleteLater() slot to ensure it is safely deleted:
+
+ \code
+ connect(thread, &QThread::finished, worker, &QObject::deleteLater);
+ \endcode
+
Note that entering and leaving a new event loop (e.g., by opening a modal
dialog) will \e not perform the deferred deletion; for the object to be
deleted, the control must return to the event loop from which deleteLater()
@@ -4069,26 +4191,19 @@ static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connect
SlotObjectGuard slotObjectGuard { c->isSlotObject ? c->slotObj : nullptr };
locker.unlock();
- QMetaCallEvent *ev = c->isSlotObject ?
- new QMetaCallEvent(c->slotObj, sender, signal, nargs) :
- new QMetaCallEvent(c->method_offset, c->method_relative, c->callFunction, sender, signal, nargs);
-
- void **args = ev->args();
- QMetaType *types = ev->types();
-
- types[0] = QMetaType(); // return type
- args[0] = nullptr; // return value
-
- if (nargs > 1) {
- for (int n = 1; n < nargs; ++n)
- types[n] = QMetaType(argumentTypes[n - 1]);
-
- for (int n = 1; n < nargs; ++n)
- args[n] = types[n].create(argv[n]);
+ QVarLengthArray<const QtPrivate::QMetaTypeInterface *> argTypes;
+ argTypes.emplace_back(nullptr); // return type
+ for (int n = 1; n < nargs; ++n) {
+ argTypes.emplace_back(QMetaType(argumentTypes[n - 1]).iface()); // convert type ids to QMetaTypeInterfaces
}
+ auto ev = c->isSlotObject ?
+ std::make_unique<QQueuedMetaCallEvent>(c->slotObj,
+ sender, signal, nargs, argTypes.data(), argv) :
+ std::make_unique<QQueuedMetaCallEvent>(c->method_offset, c->method_relative, c->callFunction,
+ sender, signal, nargs, argTypes.data(), argv);
+
if (c->isSingleShot && !QObjectPrivate::removeConnection(c)) {
- delete ev;
return;
}
@@ -4096,11 +4211,10 @@ static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connect
if (!c->isSingleShot && !c->receiver.loadRelaxed()) {
// the connection has been disconnected while we were unlocked
locker.unlock();
- delete ev;
return;
}
- QCoreApplication::postEvent(receiver, ev);
+ QCoreApplication::postEvent(receiver, ev.release());
}
template <bool callbacks_enabled>
diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h
index dca9c1af932..75aeba73583 100644
--- a/src/corelib/kernel/qobject_p.h
+++ b/src/corelib/kernel/qobject_p.h
@@ -351,7 +351,7 @@ private:
class Q_CORE_EXPORT QMetaCallEvent : public QAbstractMetaCallEvent
{
public:
- // blocking queued with latch - args always owned by caller
+ // blocking queued with latch - arguments always remain owned by the caller
QMetaCallEvent(ushort method_offset, ushort method_relative,
QObjectPrivate::StaticMetaCallFunction callFunction,
const QObject *sender, int signalId,
@@ -363,14 +363,17 @@ public:
const QObject *sender, int signalId,
void **args, QLatch *latch);
- // queued - args allocated by event, copied by caller
+ // OLD - queued - args allocated by event, copied by caller
+ Q_DECL_DEPRECATED_X("Remove this constructor once the qtdeclarative patch is merged. Arguments are now copied by the QQueuedMetaCallEvent constructor and not the caller.")
QMetaCallEvent(ushort method_offset, ushort method_relative,
QObjectPrivate::StaticMetaCallFunction callFunction,
const QObject *sender, int signalId,
int nargs);
+ Q_DECL_DEPRECATED_X("Remove this constructor once the qtdeclarative patch is merged. Arguments are now copied by the QQueuedMetaCallEvent constructor and not the caller.")
QMetaCallEvent(QtPrivate::QSlotObjectBase *slotObj,
const QObject *sender, int signalId,
int nargs);
+ Q_DECL_DEPRECATED_X("Remove this constructor once the qtdeclarative patch is merged. Arguments are now copied by the QQueuedMetaCallEvent constructor and not the caller.")
QMetaCallEvent(QtPrivate::SlotObjUniquePtr slotObj,
const QObject *sender, int signalId,
int nargs);
@@ -378,14 +381,16 @@ public:
~QMetaCallEvent() override;
inline int id() const { return d.method_offset_ + d.method_relative_; }
- inline const void * const* args() const { return d.args_; }
+ Q_DECL_DEPRECATED_X("Remove this function once the qtdeclarative patch is merged. Arguments are now copied by the QQueuedMetaCallEvent constructor and not the caller.")
inline void ** args() { return d.args_; }
- inline const QMetaType *types() const { return reinterpret_cast<QMetaType *>(d.args_ + d.nargs_); }
+ Q_DECL_DEPRECATED_X("Remove this function once the qtdeclarative patch is merged. Arguments are now copied by the QQueuedMetaCallEvent constructor and not the caller.")
inline QMetaType *types() { return reinterpret_cast<QMetaType *>(d.args_ + d.nargs_); }
virtual void placeMetaCall(QObject *object) override;
-private:
+protected:
+ // Move to QQueuedMetaCallEvent once the qtdeclarative patch is merged.
+ // QMetaCallEvent should not alloc anything anymore.
inline void allocArgs();
struct Data {
@@ -396,9 +401,50 @@ private:
ushort method_offset_;
ushort method_relative_;
} d;
- // preallocate enough space for three arguments
- alignas(void *) char prealloc_[3 * sizeof(void *) + 3 * sizeof(QMetaType)];
+
+ inline QMetaCallEvent(const QObject *sender, int signalId, Data &&data);
+ inline void * const *args() const { return d.args_; }
+ inline QMetaType const *types() const { return reinterpret_cast<QMetaType *>(d.args_ + d.nargs_); }
+
+ // Space for 5 argument pointers and types (including 1 return arg).
+ // Contiguous so that we can make one calloc() for both the pointers and the types when necessary.
+ // Move to QQueuedMetaCallEvent once the qtdeclarative patch is merged.
+ alignas(void *) char prealloc_[5 * sizeof(void *) + 5 * sizeof(QMetaType)];
+};
+
+class Q_CORE_EXPORT QQueuedMetaCallEvent : public QMetaCallEvent
+{
+public:
+ // queued - arguments are allocated and copied from argValues by these constructors
+ QQueuedMetaCallEvent(ushort method_offset, ushort method_relative,
+ QObjectPrivate::StaticMetaCallFunction callFunction,
+ const QObject *sender, int signalId,
+ int argCount, const QtPrivate::QMetaTypeInterface * const *argTypes,
+ const void * const *argValues);
+ QQueuedMetaCallEvent(QtPrivate::QSlotObjectBase *slotObj,
+ const QObject *sender, int signalId,
+ int argCount, const QtPrivate::QMetaTypeInterface * const *argTypes,
+ const void * const *argValues);
+ QQueuedMetaCallEvent(QtPrivate::SlotObjUniquePtr slotObj,
+ const QObject *sender, int signalId,
+ int argCount, const QtPrivate::QMetaTypeInterface * const *argTypes,
+ const void * const *argValues);
+
+ ~QQueuedMetaCallEvent() override;
+
+private:
+ inline void copyArgValues(int argCount, const QtPrivate::QMetaTypeInterface * const *argTypes,
+ const void * const *argValues);
+ static inline bool typeFitsInPlace(const QMetaType type);
+
+ struct ArgValueStorage { // size and alignment matching QString, QList, etc
+ static constexpr size_t MaxSize = 3 * sizeof(void *);
+ alignas(void *) char storage[MaxSize];
+ };
+ static constexpr int InplaceValuesCapacity = 3;
+ ArgValueStorage valuesPrealloc_[InplaceValuesCapacity];
};
+// The total QQueuedMetaCallEvent size is 224 bytes which is a 32-byte multiple, efficient for memory allocators.
struct QAbstractDynamicMetaObject;
struct Q_CORE_EXPORT QDynamicMetaObjectData
diff --git a/src/corelib/kernel/qsignalmapper.cpp b/src/corelib/kernel/qsignalmapper.cpp
index 65d766db4a9..96e909d1be7 100644
--- a/src/corelib/kernel/qsignalmapper.cpp
+++ b/src/corelib/kernel/qsignalmapper.cpp
@@ -74,9 +74,9 @@ public:
The only function that we need to implement is the constructor:
- \snippet qsignalmapper/buttonwidget.cpp 0
- \snippet qsignalmapper/buttonwidget.cpp 1
- \snippet qsignalmapper/buttonwidget.cpp 2
+ \snippet qsignalmapper/buttonwidget.cpp OpenCtor
+ \snippet qsignalmapper/buttonwidget.cpp OldNotation
+ \snippet qsignalmapper/buttonwidget.cpp CloseBrackets
A list of texts is passed to the constructor. A signal mapper is
constructed and for each text in the list a QPushButton is
@@ -92,7 +92,9 @@ public:
slots. The example above can be rewritten simpler without QSignalMapper
by connecting to a lambda function.
- \snippet qsignalmapper/buttonwidget.cpp 3
+ \snippet qsignalmapper/buttonwidget.cpp OpenCtor
+ \snippet qsignalmapper/buttonwidget.cpp ModernNotation
+ \snippet qsignalmapper/buttonwidget.cpp CloseBrackets
\sa QObject, QButtonGroup, QActionGroup
*/
diff --git a/src/corelib/kernel/qsystemerror.cpp b/src/corelib/kernel/qsystemerror.cpp
index 428ce62984f..62741150144 100644
--- a/src/corelib/kernel/qsystemerror.cpp
+++ b/src/corelib/kernel/qsystemerror.cpp
@@ -137,9 +137,9 @@ QString QSystemError::windowsString(int errorCode)
QString QSystemError::windowsComString(HRESULT hr)
{
const _com_error comError(hr);
- QString result = "COM error 0x"_L1 + QString::number(ulong(hr), 16);
+ QString result = u"COM error 0x"_s + QString::number(ulong(hr), 16);
if (const wchar_t *msg = comError.ErrorMessage())
- result += ": "_L1 + QString::fromWCharArray(msg);
+ result += u": "_s + QString::fromWCharArray(msg);
return result;
}
diff --git a/src/corelib/serialization/qtextstream.cpp b/src/corelib/serialization/qtextstream.cpp
index 5e0eff698f9..e4dc98af98b 100644
--- a/src/corelib/serialization/qtextstream.cpp
+++ b/src/corelib/serialization/qtextstream.cpp
@@ -711,7 +711,7 @@ void QTextStreamPrivate::write(const QChar *data, qsizetype len)
/*!
\internal
*/
-inline void QTextStreamPrivate::write(QChar ch)
+void QTextStreamPrivate::write(QChar ch)
{
if (string) {
// ### What about seek()??
@@ -845,7 +845,7 @@ void QTextStreamPrivate::putString(const QChar *data, qsizetype len, bool number
const QChar sign = len > 0 ? data[0] : QChar();
if (sign == locale.negativeSign() || sign == locale.positiveSign()) {
// write the sign before the padding, then skip it later
- write(&sign, 1);
+ write(sign);
++data;
--len;
}
@@ -874,7 +874,7 @@ void QTextStreamPrivate::putString(QLatin1StringView data, bool number)
const QChar sign = data.size() > 0 ? QLatin1Char(*data.data()) : QChar();
if (sign == locale.negativeSign() || sign == locale.positiveSign()) {
// write the sign before the padding, then skip it later
- write(&sign, 1);
+ write(sign);
data = QLatin1StringView(data.data() + 1, data.size() - 1);
}
}
diff --git a/src/corelib/serialization/qtextstream_p.h b/src/corelib/serialization/qtextstream_p.h
index 7227c29c8fe..bf3ce7b2ef7 100644
--- a/src/corelib/serialization/qtextstream_p.h
+++ b/src/corelib/serialization/qtextstream_p.h
@@ -145,7 +145,7 @@ public:
bool getReal(double *f);
inline void write(QStringView data) { write(data.begin(), data.size()); }
- inline void write(QChar ch);
+ void write(QChar ch);
void write(const QChar *data, qsizetype len);
void write(QLatin1StringView data);
void writePadding(qsizetype len);
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/corelib/tools/qduplicatetracker_p.h b/src/corelib/tools/qduplicatetracker_p.h
index 4740047356b..f2bcaf7065d 100644
--- a/src/corelib/tools/qduplicatetracker_p.h
+++ b/src/corelib/tools/qduplicatetracker_p.h
@@ -136,6 +136,12 @@ public:
set.clear();
#endif // __cpp_lib_memory_resource
}
+
+ using const_iterator = typename Set::const_iterator;
+ const_iterator begin() const { return set.cbegin(); }
+ const_iterator end() const { return set.cend(); }
+ const_iterator cbegin() const { return begin(); }
+ const_iterator cend() const { return end(); }
};
QT_END_NAMESPACE
diff --git a/src/dbus/qdbusargument.h b/src/dbus/qdbusargument.h
index 8370de74bb6..f04cbc1ed43 100644
--- a/src/dbus/qdbusargument.h
+++ b/src/dbus/qdbusargument.h
@@ -15,6 +15,8 @@
#include <QtCore/qvariant.h>
#include <QtDBus/qdbusextratypes.h>
+#include <tuple>
+
#ifndef QT_NO_DBUS
QT_BEGIN_NAMESPACE
@@ -324,7 +326,7 @@ inline const QDBusArgument &operator>>(const QDBusArgument &arg, std::pair<T1, T
template <typename... T>
QDBusArgument &operator<<(QDBusArgument &argument, const std::tuple<T...> &tuple)
{
- static_assert(std::tuple_size_v<std::tuple<T...>> != 0, "D-Bus doesn't allow empty structs");
+ static_assert(sizeof...(T) != 0, "D-Bus doesn't allow empty structs");
argument.beginStructure();
std::apply([&argument](const auto &...elements) { (argument << ... << elements); }, tuple);
argument.endStructure();
@@ -334,7 +336,7 @@ QDBusArgument &operator<<(QDBusArgument &argument, const std::tuple<T...> &tuple
template <typename... T>
const QDBusArgument &operator>>(const QDBusArgument &argument, std::tuple<T...> &tuple)
{
- static_assert(std::tuple_size_v<std::tuple<T...>> != 0, "D-Bus doesn't allow empty structs");
+ static_assert(sizeof...(T) != 0, "D-Bus doesn't allow empty structs");
argument.beginStructure();
std::apply([&argument](auto &...elements) { (argument >> ... >> elements); }, tuple);
argument.endStructure();
diff --git a/src/gui/kernel/qsurfaceformat.cpp b/src/gui/kernel/qsurfaceformat.cpp
index 59c469ae6b6..b53e1a63870 100644
--- a/src/gui/kernel/qsurfaceformat.cpp
+++ b/src/gui/kernel/qsurfaceformat.cpp
@@ -552,7 +552,7 @@ void QSurfaceFormat::setAlphaBufferSize(int size)
and used choice is the former (16-bit), for example when high dynamic range
rendering is desired.
- \since 6.10
+ \since 6.11
\sa colorComponentType()
*/
@@ -567,7 +567,7 @@ void QSurfaceFormat::setColorComponentType(ColorComponentType type)
/*!
\return the color component type.
- \since 6.10
+ \since 6.11
\sa setColorComponentType()
*/
diff --git a/src/gui/painting/qpainterpath.cpp b/src/gui/painting/qpainterpath.cpp
index b13b1bcad34..a6e540015d7 100644
--- a/src/gui/painting/qpainterpath.cpp
+++ b/src/gui/painting/qpainterpath.cpp
@@ -36,6 +36,8 @@
QT_BEGIN_NAMESPACE
+QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QPainterPathPrivate)
+
static inline bool isValidCoord(qreal c)
{
if (sizeof(qreal) >= sizeof(double))
@@ -512,6 +514,15 @@ QPainterPath::QPainterPath() noexcept
QPainterPath::QPainterPath(const QPainterPath &other) = default;
/*!
+ \fn QPainterPath::QPainterPath(QPainterPath &&other)
+ \since 6.10
+
+ Move-constructs a new painter path from \a other.
+
+ The moved-from object \a other is placed in the default-constructed state.
+*/
+
+/*!
Creates a QPainterPath object with the given \a startPoint as its
current position.
*/
@@ -3193,9 +3204,10 @@ qreal QPainterPath::slopeAtPercent(qreal t) const
/*!
\since 6.10
- Returns the section of the path between the length fractions \a f1 and \a f2. The effective range
- of the fractions are from 0, denoting the start point of the path, to 1, denoting its end point.
- The fractions are linear with respect to path length, in contrast to the percentage \e t values.
+ Returns the section of the path between the length fractions \a fromFraction and \a toFraction.
+ The effective range of the fractions are from 0, denoting the start point of the path, to 1,
+ denoting its end point. The fractions are linear with respect to path length, in contrast to the
+ percentage \e t values.
The value of \a offset will be added to the fraction values. If that causes an over- or underflow
of the [0, 1] range, the values will be wrapped around, as will the resulting path. The effective
@@ -3206,13 +3218,13 @@ qreal QPainterPath::slopeAtPercent(qreal t) const
\sa length(), percentAtLength(), setCachingEnabled()
*/
-QPainterPath QPainterPath::trimmed(qreal f1, qreal f2, qreal offset) const
+QPainterPath QPainterPath::trimmed(qreal fromFraction, qreal toFraction, qreal offset) const
{
if (isEmpty())
return *this;
- f1 = qBound(qreal(0), f1, qreal(1));
- f2 = qBound(qreal(0), f2, qreal(1));
+ qreal f1 = qBound(qreal(0), fromFraction, qreal(1));
+ qreal f2 = qBound(qreal(0), toFraction, qreal(1));
if (f1 > f2)
qSwap(f1, f2);
if (qFuzzyCompare(f2 - f1, qreal(1))) // Shortcut for no trimming
diff --git a/src/gui/painting/qpainterpath.h b/src/gui/painting/qpainterpath.h
index 2d502936dfd..2e449a8835e 100644
--- a/src/gui/painting/qpainterpath.h
+++ b/src/gui/painting/qpainterpath.h
@@ -17,7 +17,6 @@ QT_BEGIN_NAMESPACE
class QFont;
class QPainterPathPrivate;
-struct QPainterPathPrivateDeleter;
class QPainterPathStrokerPrivate;
class QPen;
class QPolygonF;
@@ -25,6 +24,7 @@ class QRegion;
class QTransform;
class QVectorPath;
+QT_DECLARE_QESDP_SPECIALIZATION_DTOR(QPainterPathPrivate)
class Q_GUI_EXPORT QPainterPath
{
public:
@@ -56,6 +56,7 @@ public:
explicit QPainterPath(const QPointF &startPoint);
QPainterPath(const QPainterPath &other);
QPainterPath &operator=(const QPainterPath &other);
+ QPainterPath(QPainterPath &&other) noexcept = default;
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QPainterPath)
~QPainterPath();
@@ -141,7 +142,7 @@ public:
QPointF pointAtPercent(qreal t) const;
qreal angleAtPercent(qreal t) const;
qreal slopeAtPercent(qreal t) const;
- [[nodiscard]] QPainterPath trimmed(qreal f1, qreal f2, qreal offset = 0) const;
+ [[nodiscard]] QPainterPath trimmed(qreal fromFraction, qreal toFraction, qreal offset = 0) const;
bool intersects(const QPainterPath &p) const;
bool contains(const QPainterPath &p) const;
diff --git a/src/gui/painting/qpainterpath_p.h b/src/gui/painting/qpainterpath_p.h
index de8aedb5be4..aaa22355cd8 100644
--- a/src/gui/painting/qpainterpath_p.h
+++ b/src/gui/painting/qpainterpath_p.h
@@ -100,7 +100,6 @@ public:
friend class QPainterPathStrokerPrivate;
friend class QTransform;
friend class QVectorPath;
- friend struct QPainterPathPrivateDeleter;
#ifndef QT_NO_DATASTREAM
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QPainterPath &);
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QPainterPath &);
diff --git a/src/gui/util/qgridlayoutengine.cpp b/src/gui/util/qgridlayoutengine.cpp
index e8a6b56ae20..32fee3bcdf7 100644
--- a/src/gui/util/qgridlayoutengine.cpp
+++ b/src/gui/util/qgridlayoutengine.cpp
@@ -471,6 +471,7 @@ void QGridLayoutRowData::dump(int indent) const
qDebug("%*s Multi-cell entry <%d, %d> (stretch %d)", indent, "", it.key().first,
it.key().second, it.value().q_stretch);
it.value().q_box.dump(indent + 2);
+ ++it;
}
}
#endif
diff --git a/src/network/kernel/qnetworkproxy_android.cpp b/src/network/kernel/qnetworkproxy_android.cpp
index d5b56bba865..2261572fea7 100644
--- a/src/network/kernel/qnetworkproxy_android.cpp
+++ b/src/network/kernel/qnetworkproxy_android.cpp
@@ -3,6 +3,7 @@
#include "qnetworkproxy.h"
+#include <QtCore/qapplicationstatic.h>
#include <QtCore/qcoreapplication_platform.h>
#include <QtCore/qjnienvironment.h>
#include <QtCore/qjniobject.h>
@@ -21,7 +22,7 @@ public:
using namespace QNativeInterface;
using namespace QtJniTypes;
-Q_GLOBAL_STATIC(ProxyInfoObject, proxyInfoInstance)
+Q_APPLICATION_STATIC(ProxyInfoObject, proxyInfoInstance)
Q_DECLARE_JNI_CLASS(QtNetwork, "org/qtproject/qt/android/network/QtNetwork")
Q_DECLARE_JNI_CLASS(ProxyInfo, "android/net/ProxyInfo")
diff --git a/src/plugins/platforms/android/androidcontentfileengine.cpp b/src/plugins/platforms/android/androidcontentfileengine.cpp
index 6c02a73e7c8..7efe4d52d4c 100644
--- a/src/plugins/platforms/android/androidcontentfileengine.cpp
+++ b/src/plugins/platforms/android/androidcontentfileengine.cpp
@@ -1,7 +1,7 @@
// Copyright (C) 2019 Volker Krause <[email protected]>
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-// Qt-Security score:critical reason:file-handling
+// Qt-Security score:critical reason:data-parser
#include "androidcontentfileengine.h"
diff --git a/src/plugins/platforms/android/extract.cpp b/src/plugins/platforms/android/extract.cpp
index 48a2c4ecfaf..9160470e0cc 100644
--- a/src/plugins/platforms/android/extract.cpp
+++ b/src/plugins/platforms/android/extract.cpp
@@ -1,7 +1,6 @@
// Copyright (C) 2021 The Qt Company Ltd.
// Copyright (C) 2014 BogDan Vatra <[email protected]>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-// Qt-Security score:critical reason:data-serializing
#include <QtCore/QJniEnvironment>
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
diff --git a/src/plugins/platforms/ios/qiosapplicationdelegate.mm b/src/plugins/platforms/ios/qiosapplicationdelegate.mm
index a01c590bba8..990409f2d17 100644
--- a/src/plugins/platforms/ios/qiosapplicationdelegate.mm
+++ b/src/plugins/platforms/ios/qiosapplicationdelegate.mm
@@ -73,22 +73,23 @@
UIWindowScene *windowScene = static_cast<UIWindowScene*>(scene);
QUIWindow *window = [[QUIWindow alloc] initWithWindowScene:windowScene];
+ window.rootViewController = [[[QIOSViewController alloc] initWithWindow:window] autorelease];
- QIOSScreen *screen = [&]{
- for (auto *screen : qGuiApp->screens()) {
- auto *platformScreen = static_cast<QIOSScreen*>(screen->handle());
-#if !defined(Q_OS_VISIONOS)
- if (platformScreen->uiScreen() == windowScene.screen)
-#endif
- return platformScreen;
- }
- Q_UNREACHABLE();
- }();
+ self.window = [window autorelease];
+}
- window.rootViewController = [[[QIOSViewController alloc]
- initWithWindow:window andScreen:screen] autorelease];
+- (void)windowScene:(UIWindowScene *)windowScene
+ didUpdateCoordinateSpace:(id<UICoordinateSpace>)previousCoordinateSpace
+ interfaceOrientation:(UIInterfaceOrientation)previousInterfaceOrientation
+ traitCollection:(UITraitCollection *)previousTraitCollection
+{
+ qCDebug(lcQpaWindowScene) << "Scene" << windowScene << "did update properties";
+ if (!self.window)
+ return;
- self.window = [window autorelease];
+ Q_ASSERT([self.window isKindOfClass:QUIWindow.class]);
+ auto *viewController = static_cast<QIOSViewController*>(self.window.rootViewController);
+ [viewController updatePlatformScreen];
}
- (void)sceneDidDisconnect:(UIScene *)scene
diff --git a/src/plugins/platforms/ios/qiosglobal.mm b/src/plugins/platforms/ios/qiosglobal.mm
index 9ab490b2970..89a343061ee 100644
--- a/src/plugins/platforms/ios/qiosglobal.mm
+++ b/src/plugins/platforms/ios/qiosglobal.mm
@@ -13,7 +13,7 @@
QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcQpaApplication, "qt.qpa.application");
-Q_LOGGING_CATEGORY(lcQpaInputMethods, "qt.qpa.input.methods");
+Q_LOGGING_CATEGORY(lcQpaInputMethods, "qt.qpa.input.methods", QtCriticalMsg);
Q_LOGGING_CATEGORY(lcQpaWindow, "qt.qpa.window");
Q_LOGGING_CATEGORY(lcQpaWindowScene, "qt.qpa.window.scene");
diff --git a/src/plugins/platforms/ios/qiosinputcontext.mm b/src/plugins/platforms/ios/qiosinputcontext.mm
index 2926e6788ba..8544c497d43 100644
--- a/src/plugins/platforms/ios/qiosinputcontext.mm
+++ b/src/plugins/platforms/ios/qiosinputcontext.mm
@@ -640,8 +640,10 @@ void QIOSInputContext::update(Qt::InputMethodQueries updatedProperties)
// focus object. We try to detect code paths that fail this assertion and smooth
// over the situation by doing a manual update of the focus object.
if (qApp->focusObject() != m_imeState.focusObject && updatedProperties != Qt::ImQueryAll) {
- qWarning() << "stale focus object" << static_cast<void *>(m_imeState.focusObject)
- << ", doing manual update";
+ qCWarning(lcQpaInputMethods).verbosity(0) << "Updating input context" << updatedProperties
+ << "with last reported focus object" << m_imeState.focusObject
+ << "but qGuiApp reports" << qApp->focusObject()
+ << "which means someone failed to call QPlatformInputContext::setFocusObject()";
setFocusObject(qApp->focusObject());
return;
}
diff --git a/src/plugins/platforms/ios/qiosviewcontroller.h b/src/plugins/platforms/ios/qiosviewcontroller.h
index 340cc6b6acb..b5ce88d6a33 100644
--- a/src/plugins/platforms/ios/qiosviewcontroller.h
+++ b/src/plugins/platforms/ios/qiosviewcontroller.h
@@ -12,10 +12,12 @@ QT_END_NAMESPACE
@interface QIOSViewController : UIViewController
-- (instancetype)initWithWindow:(UIWindow*)window andScreen:(QT_PREPEND_NAMESPACE(QIOSScreen) *)screen;
+- (instancetype)initWithWindow:(UIWindow*)window;
- (void)updateStatusBarProperties;
- (NSArray*)keyCommands;
- (void)handleShortcut:(UIKeyCommand*)keyCommand;
+- (void)updatePlatformScreen;
+
#ifndef Q_OS_TVOS
// UIViewController
diff --git a/src/plugins/platforms/ios/qiosviewcontroller.mm b/src/plugins/platforms/ios/qiosviewcontroller.mm
index b6b42c59b0b..169f8ae1754 100644
--- a/src/plugins/platforms/ios/qiosviewcontroller.mm
+++ b/src/plugins/platforms/ios/qiosviewcontroller.mm
@@ -231,11 +231,12 @@
@synthesize preferredStatusBarStyle;
#endif
-- (instancetype)initWithWindow:(UIWindow*)window andScreen:(QT_PREPEND_NAMESPACE(QIOSScreen) *)screen
+- (instancetype)initWithWindow:(UIWindow*)window
{
if (self = [self init]) {
self.window = window;
- self.platformScreen = screen;
+ self.platformScreen = nil;
+ [self updatePlatformScreen];
self.changingOrientation = NO;
#ifndef Q_OS_TVOS
@@ -314,6 +315,54 @@
// -------------------------------------------------------------------------
+- (void)updatePlatformScreen
+{
+ auto *windowScene = self.window.windowScene;
+
+ QIOSScreen *newPlatformScreen = [&]{
+ for (auto *screen : qGuiApp->screens()) {
+ auto *platformScreen = static_cast<QIOSScreen*>(screen->handle());
+#if !defined(Q_OS_VISIONOS)
+ if (platformScreen->uiScreen() == windowScene.screen)
+#endif
+ return platformScreen;
+ }
+ Q_UNREACHABLE();
+ }();
+
+ if (newPlatformScreen != self.platformScreen) {
+ QIOSScreen *oldPlatformScreen = self.platformScreen;
+ self.platformScreen = newPlatformScreen;
+
+ qCDebug(lcQpaWindow) << "View controller" << self << "moved from"
+ << oldPlatformScreen << "to" << newPlatformScreen;
+
+ QScreen *newScreen = newPlatformScreen ? newPlatformScreen->screen() : nullptr;
+
+ const bool isPrimaryScene = !qt_apple_sharedApplication().supportsMultipleScenes
+ && windowScene.session.role == UIWindowSceneSessionRoleApplication;
+
+ if (isPrimaryScene) {
+ // When we only have a single application-role scene we treat the
+ // active screen as the primary one, so that windows shown on the
+ // primary screen end up in our view controller.
+ QWindowSystemInterface::handlePrimaryScreenChanged(newPlatformScreen);
+ }
+
+ for (auto *window : qGuiApp->topLevelWindows()) {
+ // Move window to new screen if it was on the old screen,
+ // or if we're setting up the primary scene, in which case
+ // we want to adopt all existing windows to this screen.
+ if ((window->screen()->handle() == oldPlatformScreen)
+ || (isPrimaryScene && !oldPlatformScreen)) {
+ QWindowSystemInterface::handleWindowScreenChanged(window, newScreen);
+ }
+ }
+ }
+}
+
+// -------------------------------------------------------------------------
+
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration
{
self.changingOrientation = YES;
diff --git a/src/plugins/styles/modernwindows/qwindows11style.cpp b/src/plugins/styles/modernwindows/qwindows11style.cpp
index 7ae48a302f4..62269a21de1 100644
--- a/src/plugins/styles/modernwindows/qwindows11style.cpp
+++ b/src/plugins/styles/modernwindows/qwindows11style.cpp
@@ -183,30 +183,24 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt
QObject *styleObject = option->styleObject; // Can be widget or qquickitem
QRectF thumbRect = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
- auto center = thumbRect.center();
const qreal outerRadius = qMin(8.0, (slider->orientation == Qt::Horizontal ? thumbRect.height() / 2.0 : thumbRect.width() / 2.0) - 1);
-
- thumbRect.setWidth(outerRadius);
- thumbRect.setHeight(outerRadius);
- thumbRect.moveCenter(center);
- QPointF cursorPos = widget ? widget->mapFromGlobal(QCursor::pos()) : QPointF();
- bool isInsideHandle = thumbRect.contains(cursorPos);
+ bool isInsideHandle = option->activeSubControls == SC_SliderHandle;
bool oldIsInsideHandle = styleObject->property("_q_insidehandle").toBool();
- int oldState = styleObject->property("_q_stylestate").toInt();
- int oldActiveControls = styleObject->property("_q_stylecontrols").toInt();
+ State oldState = State(styleObject->property("_q_stylestate").toInt());
+ SubControls oldActiveControls = SubControls(styleObject->property("_q_stylecontrols").toInt());
QRectF oldRect = styleObject->property("_q_stylerect").toRect();
styleObject->setProperty("_q_insidehandle", isInsideHandle);
- styleObject->setProperty("_q_stylestate", int(option->state));
+ styleObject->setProperty("_q_stylestate", int(state));
styleObject->setProperty("_q_stylecontrols", int(option->activeSubControls));
styleObject->setProperty("_q_stylerect", option->rect);
if (option->styleObject->property("_q_end_radius").isNull())
option->styleObject->setProperty("_q_end_radius", outerRadius * 0.43);
bool doTransition = (((state & State_Sunken) != (oldState & State_Sunken)
- || ((oldIsInsideHandle) != (isInsideHandle))
- || oldActiveControls != int(option->activeSubControls))
+ || (oldIsInsideHandle != isInsideHandle)
+ || (oldActiveControls != option->activeSubControls))
&& state & State_Enabled);
if (oldRect != option->rect) {
@@ -374,31 +368,29 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt
}
}
if (sub & SC_SliderHandle) {
- if (const auto *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
- const QRectF rect = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
- const QPointF center = rect.center();
+ const QRectF rect = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
+ const QPointF center = rect.center();
- const QNumberStyleAnimation* animation = qobject_cast<QNumberStyleAnimation*>(d->animation(option->styleObject));
+ const QNumberStyleAnimation* animation = qobject_cast<QNumberStyleAnimation*>(d->animation(option->styleObject));
- if (animation != nullptr)
- option->styleObject->setProperty("_q_inner_radius", animation->currentValue());
- else
- option->styleObject->setProperty("_q_inner_radius", option->styleObject->property("_q_end_radius"));
-
- const qreal outerRadius = qMin(8.0,(slider->orientation == Qt::Horizontal ? rect.height() / 2.0 : rect.width() / 2.0) - 1);
- const float innerRadius = option->styleObject->property("_q_inner_radius").toFloat();
- painter->setRenderHint(QPainter::Antialiasing, true);
- painter->setPen(Qt::NoPen);
- painter->setBrush(WINUI3Colors[colorSchemeIndex][controlFillSolid]);
- painter->drawEllipse(center, outerRadius, outerRadius);
- painter->setBrush(option->palette.accent());
- painter->drawEllipse(center, innerRadius, innerRadius);
-
- painter->setPen(WINUI3Colors[colorSchemeIndex][controlStrokeSecondary]);
- painter->setBrush(Qt::NoBrush);
- painter->drawEllipse(center, outerRadius + 0.5, outerRadius + 0.5);
- painter->drawEllipse(center, innerRadius + 0.5, innerRadius + 0.5);
- }
+ float innerRadius = 0;
+ if (animation != nullptr)
+ innerRadius = animation->currentValue();
+ else
+ innerRadius = option->styleObject->property("_q_end_radius").toFloat();
+ option->styleObject->setProperty("_q_inner_radius", innerRadius);
+ const qreal outerRadius = qMin(8.0,(slider->orientation == Qt::Horizontal ? rect.height() / 2.0 : rect.width() / 2.0) - 1);
+
+ painter->setPen(Qt::NoPen);
+ painter->setBrush(winUI3Color(controlFillSolid));
+ painter->drawEllipse(center, outerRadius, outerRadius);
+ painter->setBrush(option->palette.accent());
+ painter->drawEllipse(center, innerRadius, innerRadius);
+
+ painter->setPen(winUI3Color(controlStrokeSecondary));
+ painter->setBrush(Qt::NoBrush);
+ painter->drawEllipse(center, outerRadius + 0.5, outerRadius + 0.5);
+ painter->drawEllipse(center, innerRadius + 0.5, innerRadius + 0.5);
}
if (slider->state & State_HasFocus) {
QStyleOptionFocusRect fropt;
@@ -1684,18 +1676,13 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op
}
const bool highlightCurrent = vopt->state.testAnyFlags(State_Selected | State_MouseOver);
if (highlightCurrent) {
- const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(widget);
- if (highContrastTheme)
+ if (highContrastTheme) {
painter->setBrush(vopt->palette.highlight());
- else
- painter->setBrush(view->alternatingRowColors() ? vopt->palette.highlight() : WINUI3Colors[colorSchemeIndex][subtleHighlightColor]);
- QWidget *editorWidget = view ? view->indexWidget(view->currentIndex()) : nullptr;
- if (editorWidget) {
- QPalette pal = editorWidget->palette();
- QColor editorBgColor = vopt->backgroundBrush == Qt::NoBrush ? vopt->palette.color(widget->backgroundRole()) : vopt->backgroundBrush.color();
- editorBgColor.setAlpha(255);
- pal.setColor(editorWidget->backgroundRole(), editorBgColor);
- editorWidget->setPalette(pal);
+ } else {
+ const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(widget);
+ painter->setBrush(view && view->alternatingRowColors()
+ ? vopt->palette.highlight()
+ : winUI3Color(subtleHighlightColor));
}
} else {
painter->setBrush(vopt->backgroundBrush);
@@ -2237,10 +2224,11 @@ static void populateLightSystemBasePalette(QPalette &result)
static QString oldStyleSheet;
const bool styleSheetChanged = oldStyleSheet != qApp->styleSheet();
- const QColor textColor = QColor(0x00,0x00,0x00,0xE4);
- const QColor textDisabled = QColor(0x00,0x00,0x00,0x5C);
- const QColor btnFace = QColor(0xFF,0xFF,0xFF,0xB3);
- const QColor alternateBase = QColor(0x00,0x00,0x00,0x09);
+ constexpr QColor textColor = QColor(0x00,0x00,0x00,0xE4);
+ constexpr QColor textDisabled = QColor(0x00, 0x00, 0x00, 0x5C);
+ constexpr QColor btnFace = QColor(0xFF, 0xFF, 0xFF, 0xB3);
+ constexpr QColor base = QColor(0xFF, 0xFF, 0xFF, 0xFF);
+ constexpr QColor alternateBase = QColor(0x00, 0x00, 0x00, 0x09);
const QColor btnHighlight = result.accent().color();
const QColor btnColor = result.button().color();
@@ -2252,7 +2240,7 @@ static void populateLightSystemBasePalette(QPalette &result)
SET_IF_UNRESOLVED(QPalette::Active, QPalette::Mid, btnColor.darker(150));
SET_IF_UNRESOLVED(QPalette::Active, QPalette::Text, textColor);
SET_IF_UNRESOLVED(QPalette::Active, QPalette::BrightText, btnHighlight);
- SET_IF_UNRESOLVED(QPalette::Active, QPalette::Base, btnFace);
+ SET_IF_UNRESOLVED(QPalette::Active, QPalette::Base, base);
SET_IF_UNRESOLVED(QPalette::Active, QPalette::Window, QColor(0xF3,0xF3,0xF3,0xFF));
SET_IF_UNRESOLVED(QPalette::Active, QPalette::ButtonText, textColor);
SET_IF_UNRESOLVED(QPalette::Active, QPalette::Midlight, btnColor.lighter(125));
@@ -2269,7 +2257,7 @@ static void populateLightSystemBasePalette(QPalette &result)
SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Mid, btnColor.darker(150));
SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Text, textColor);
SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::BrightText, btnHighlight);
- SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Base, btnFace);
+ SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Base, base);
SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Window, QColor(0xF3,0xF3,0xF3,0xFF));
SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::ButtonText, textColor);
SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Midlight, btnColor.lighter(125));
@@ -2290,7 +2278,7 @@ static void populateDarkSystemBasePalette(QPalette &result)
static QString oldStyleSheet;
const bool styleSheetChanged = oldStyleSheet != qApp->styleSheet();
- const QColor alternateBase = QColor(0xFF,0xFF,0xFF,0x0F);
+ constexpr QColor alternateBase = QColor(0xFF, 0xFF, 0xFF, 0x0F);
SET_IF_UNRESOLVED(QPalette::Active, QPalette::AlternateBase, alternateBase);
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp
index f9d58e4d906..acb63c4aa9b 100644
--- a/src/widgets/dialogs/qmessagebox.cpp
+++ b/src/widgets/dialogs/qmessagebox.cpp
@@ -562,6 +562,10 @@ void QMessageBoxPrivate::helperClicked(QPlatformDialogHelper::StandardButton hel
and \l{QMessageBox::standardButtons} {standard buttons} for
accepting a user response.
+ While the parent parameter is optional, specifying it gives a hint
+ to the window manager, which can then take care of positioning, and
+ maintain a proper stacking order of the dialog window.
+
Two APIs for using QMessageBox are provided, the property-based
API, and the static functions. Calling one of the static functions
is the simpler approach, but it is less flexible than using the
diff --git a/src/widgets/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp b/src/widgets/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp
index ebc07025ec0..062e2e5142a 100644
--- a/src/widgets/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp
+++ b/src/widgets/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp
@@ -12,7 +12,7 @@ int ret = QMessageBox::warning(this, tr("My Application"),
//! [2]
-QMessageBox msgBox;
+QMessageBox msgBox(this);
QPushButton *connectButton = msgBox.addButton(tr("Connect"), QMessageBox::ActionRole);
QPushButton *abortButton = msgBox.addButton(QMessageBox::Abort);
@@ -53,13 +53,13 @@ int main(int argc, char *argv[])
//! [4]
//! [5]
-QMessageBox msgBox;
+QMessageBox msgBox(this);
msgBox.setText("The document has been modified.");
msgBox.exec();
//! [5]
//! [6]
-QMessageBox msgBox;
+QMessageBox msgBox(this);
msgBox.setText("The document has been modified.");
msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index 08178e7b685..f4b21d3b70d 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -5269,7 +5269,11 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op
if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
if (rule.baseStyleCanDraw()) {
sz = baseStyle()->sizeFromContents(ct, opt, sz, w);
- } else if (spinbox->buttonSymbols != QAbstractSpinBox::NoButtons) {
+ if (rule.hasBox() || !rule.hasNativeBorder())
+ sz = rule.boxSize(sz);
+ return sz;
+ }
+ if (spinbox->buttonSymbols != QAbstractSpinBox::NoButtons) {
// Add some space for the up/down buttons
QRenderRule subRule = renderRule(w, opt, PseudoElement_SpinBoxUpButton);
if (subRule.hasDrawable()) {
diff --git a/src/widgets/widgets/qtoolbararealayout.cpp b/src/widgets/widgets/qtoolbararealayout.cpp
index 54c21b60387..0d7227eb038 100644
--- a/src/widgets/widgets/qtoolbararealayout.cpp
+++ b/src/widgets/widgets/qtoolbararealayout.cpp
@@ -564,19 +564,19 @@ int QToolBarAreaLayoutInfo::distance(const QPoint &pos) const
{
switch (dockPos) {
case QInternal::LeftDock:
- if (pos.y() < rect.bottom())
+ if (pos.y() > 0 && pos.y() < rect.bottom())
return pos.x() - rect.right();
break;
case QInternal::RightDock:
- if (pos.y() < rect.bottom())
+ if (pos.y() > 0 && pos.y() < rect.bottom())
return rect.left() - pos.x();
break;
case QInternal::TopDock:
- if (pos.x() < rect.right())
+ if (pos.x() > 0 && pos.x() < rect.right())
return pos.y() - rect.bottom();
break;
case QInternal::BottomDock:
- if (pos.x() < rect.right())
+ if (pos.x() > 0 && pos.x() < rect.right())
return rect.top() - pos.y();
break;