summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/doc')
-rw-r--r--src/corelib/doc/include/QtCoreDoc1
-rw-r--r--src/corelib/doc/qtcore.qdocconf13
-rw-r--r--src/corelib/doc/snippets/cmake-macros/deployment.cmake4
-rw-r--r--src/corelib/doc/snippets/cmake-macros/examples.cmake42
-rw-r--r--src/corelib/doc/snippets/cmake-macros/examples.cpp16
-rw-r--r--src/corelib/doc/snippets/code/doc_src_containers.cpp21
-rw-r--r--src/corelib/doc/snippets/code/doc_src_properties.cpp5
-rw-r--r--src/corelib/doc/snippets/code/doc_src_qalgorithms.cpp9
-rw-r--r--src/corelib/doc/snippets/code/doc_src_qiterator.cpp9
-rw-r--r--src/corelib/doc/snippets/code/doc_src_qnamespace.qdoc2
-rw-r--r--src/corelib/doc/snippets/code/doc_src_qplugin.cpp6
-rw-r--r--src/corelib/doc/snippets/code/doc_src_qset.cpp46
-rw-r--r--src/corelib/doc/snippets/code/doc_src_resources.cpp13
-rw-r--r--src/corelib/doc/snippets/code/doc_src_resources.qdoc6
-rw-r--r--src/corelib/doc/snippets/code/qlogging/qlogging.cpp10
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp3
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp69
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_io_qabstractfileengine.cpp47
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_io_qdirlisting.cpp70
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_io_qfile.cpp10
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_io_qfileinfo.cpp61
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_io_qsettings.cpp8
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_io_qstorageinfo.cpp2
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp6
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp10
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp10
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp8
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qdeadlinetimer.cpp12
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp10
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qmimedata.cpp2
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp58
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp2
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp4
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qtimer.cpp2
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp7
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_serialization_qcborstream.cpp12
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_serialization_qdatastream.cpp8
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_text_qbytearray.cpp23
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_text_qstaticlatin1stringmatcher.cpp8
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_text_qstringconverter.cpp24
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp63
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_thread_qmutexpool.cpp24
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_thread_qsemaphore.cpp6
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp16
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser.cpp8
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp84
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qlist.cpp16
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp132
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qmultimap.cpp90
-rw-r--r--src/corelib/doc/snippets/code/src_corelib_tools_qqueue.cpp2
-rw-r--r--src/corelib/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp111
-rw-r--r--src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp8
-rw-r--r--src/corelib/doc/snippets/customtype/customtypeexample.cpp90
-rw-r--r--src/corelib/doc/snippets/jni/src_qjniobject.cpp17
-rw-r--r--src/corelib/doc/snippets/ntfsp.cpp15
-rw-r--r--src/corelib/doc/snippets/qloggingcategory/main.cpp14
-rw-r--r--src/corelib/doc/snippets/qmessageauthenticationcode/main.cpp8
-rw-r--r--src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp2
-rw-r--r--src/corelib/doc/snippets/qstring/main.cpp10
-rw-r--r--src/corelib/doc/snippets/qstring/stringbuilder.cpp27
-rw-r--r--src/corelib/doc/snippets/qstringlist/main.cpp9
-rw-r--r--src/corelib/doc/snippets/resource-system/CMakeLists.txt2
-rw-r--r--src/corelib/doc/snippets/resource-system/application.pro4
-rw-r--r--src/corelib/doc/snippets/resource-system/mainwindow.cpp72
-rw-r--r--src/corelib/doc/snippets/signalsandslots/signalsandslots.h2
-rw-r--r--src/corelib/doc/snippets/threads/threads.cpp6
-rw-r--r--src/corelib/doc/snippets/timers/analogclock.cpp46
-rw-r--r--src/corelib/doc/snippets/timers/timers.cpp44
-rw-r--r--src/corelib/doc/src/animation.qdoc2
-rw-r--r--src/corelib/doc/src/cbor.qdoc3
-rw-r--r--src/corelib/doc/src/cmake/cmake-commands.qdoc1
-rw-r--r--src/corelib/doc/src/cmake/cmake-configure-variables.qdoc279
-rw-r--r--src/corelib/doc/src/cmake/cmake-deploy-variables.qdoc65
-rw-r--r--src/corelib/doc/src/cmake/cmake-properties.qdoc187
-rw-r--r--src/corelib/doc/src/cmake/cmake-standard-properties.qdoc24
-rw-r--r--src/corelib/doc/src/cmake/policy/qtp0002.qdoc63
-rw-r--r--src/corelib/doc/src/cmake/policy/qtp0003.qdoc46
-rw-r--r--src/corelib/doc/src/cmake/qt_add_big_resources.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_add_binary_resources.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_add_executable.qdoc4
-rw-r--r--src/corelib/doc/src/cmake/qt_add_library.qdoc10
-rw-r--r--src/corelib/doc/src/cmake/qt_add_plugin.qdoc5
-rw-r--r--src/corelib/doc/src/cmake/qt_add_resources.qdoc6
-rw-r--r--src/corelib/doc/src/cmake/qt_allow_non_utf8_sources.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_android_add_apk_target.qdoc4
-rw-r--r--src/corelib/doc/src/cmake/qt_android_apply_arch_suffix.qdoc5
-rw-r--r--src/corelib/doc/src/cmake/qt_android_generate_deployment_settings.qdoc5
-rw-r--r--src/corelib/doc/src/cmake/qt_deploy_qt_conf.qdoc7
-rw-r--r--src/corelib/doc/src/cmake/qt_deploy_runtime_dependencies.qdoc80
-rw-r--r--src/corelib/doc/src/cmake/qt_deploy_translations.qdoc4
-rw-r--r--src/corelib/doc/src/cmake/qt_disable_unicode_defines.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_extract_metatypes.qdoc16
-rw-r--r--src/corelib/doc/src/cmake/qt_finalize_project.qdoc4
-rw-r--r--src/corelib/doc/src/cmake/qt_finalize_target.qdoc10
-rw-r--r--src/corelib/doc/src/cmake/qt_generate_deploy_app_script.qdoc50
-rw-r--r--src/corelib/doc/src/cmake/qt_generate_deploy_script.qdoc7
-rw-r--r--src/corelib/doc/src/cmake/qt_generate_moc.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_import_plugins.qdoc36
-rw-r--r--src/corelib/doc/src/cmake/qt_policy.qdoc65
-rw-r--r--src/corelib/doc/src/cmake/qt_set_finalizer_mode.qdoc2
-rw-r--r--src/corelib/doc/src/cmake/qt_standard_project_setup.qdoc35
-rw-r--r--src/corelib/doc/src/cmake/qt_wrap_cpp.qdoc40
-rw-r--r--src/corelib/doc/src/containers.qdoc26
-rw-r--r--src/corelib/doc/src/custom-types.qdoc31
-rw-r--r--src/corelib/doc/src/datastreamformat.qdoc45
-rw-r--r--src/corelib/doc/src/external-resources.qdoc40
-rw-r--r--src/corelib/doc/src/foreach-keyword.qdoc16
-rw-r--r--src/corelib/doc/src/includes/android-content-uri-limitations.qdocinc13
-rw-r--r--src/corelib/doc/src/includes/cmake-android-qt-finalize-project-warning.qdocinc2
-rw-r--r--src/corelib/doc/src/includes/cmake-deploy-modified-variable-values.qdocinc6
-rw-r--r--src/corelib/doc/src/includes/cmake-deploy-runtime-dependencies-deploy-tool-options.qdocinc20
-rw-r--r--src/corelib/doc/src/includes/cmake-deploy-runtime-dependencies.qdocinc2
-rw-r--r--src/corelib/doc/src/includes/cmake-deploy-var-usage.qdocinc4
-rw-r--r--src/corelib/doc/src/includes/cmake-generate-deploy-app-script-deploy-tool-options.qdocinc16
-rw-r--r--src/corelib/doc/src/includes/cmake-generate-deploy-app-script.qdocinc21
-rw-r--r--src/corelib/doc/src/includes/models.qdocinc14
-rw-r--r--src/corelib/doc/src/includes/qstring.qdocinc36
-rw-r--r--src/corelib/doc/src/io.qdoc2
-rw-r--r--src/corelib/doc/src/ipc.qdoc492
-rw-r--r--src/corelib/doc/src/jni.qdoc230
-rw-r--r--src/corelib/doc/src/json.qdoc6
-rw-r--r--src/corelib/doc/src/objectmodel/bindableproperties.qdoc6
-rw-r--r--src/corelib/doc/src/objectmodel/metaobjects.qdoc5
-rw-r--r--src/corelib/doc/src/objectmodel/properties.qdoc40
-rw-r--r--src/corelib/doc/src/objectmodel/signalsandslots.qdoc8
-rw-r--r--src/corelib/doc/src/qt6-changes.qdoc2
-rw-r--r--src/corelib/doc/src/qtcore-index.qdoc2
-rw-r--r--src/corelib/doc/src/qtcore.qdoc14
-rw-r--r--src/corelib/doc/src/qtserialization.qdoc145
-rw-r--r--src/corelib/doc/src/resource-system.qdoc53
-rw-r--r--src/corelib/doc/src/timers.qdoc112
131 files changed, 2942 insertions, 1149 deletions
diff --git a/src/corelib/doc/include/QtCoreDoc b/src/corelib/doc/include/QtCoreDoc
index f3c875e49a..5f5490cbc9 100644
--- a/src/corelib/doc/include/QtCoreDoc
+++ b/src/corelib/doc/include/QtCoreDoc
@@ -1,3 +1,4 @@
#include <QtCore/QtCore>
#include "../../platform/android/qandroidextras_p.h"
#include "../../kernel/qpermissions.h"
+#include "../../tools/qatomicscopedvaluerollback_p.h"
diff --git a/src/corelib/doc/qtcore.qdocconf b/src/corelib/doc/qtcore.qdocconf
index f0a9fcc573..4ed46ae6dd 100644
--- a/src/corelib/doc/qtcore.qdocconf
+++ b/src/corelib/doc/qtcore.qdocconf
@@ -43,7 +43,8 @@ exampledirs += \
../../../examples/corelib \
../../../examples/network/dnslookup \
../../../examples/widgets/tools \
- ../../../tests/auto/corelib/thread/qpromise/
+ ../../../tests/auto/corelib/thread/qpromise \
+ ../../tools/androiddeployqt
imagedirs += images
@@ -59,5 +60,11 @@ excludefiles += ../kernel/qtestsupport_core.cpp
navigation.landingpage = "Qt Core"
navigation.cppclassespage = "Qt Core C++ Classes"
-# Fail the documentation build if there are more warnings than the limit
-warninglimit = 0
+# Highlighted examples in Data Processing & IO category
+manifestmeta.highlighted.names = \
+ "QtCore/Mandelbrot" \
+ "QtCore/Serialization Converter" \
+ "QtCore/QXmlStream Bookmarks Example"
+
+# Temporarily allow warning: No such parameter 'other' in QFlags::operator=()
+warninglimit = 1
diff --git a/src/corelib/doc/snippets/cmake-macros/deployment.cmake b/src/corelib/doc/snippets/cmake-macros/deployment.cmake
index c5979a9ff2..ef7aa726c0 100644
--- a/src/corelib/doc/snippets/cmake-macros/deployment.cmake
+++ b/src/corelib/doc/snippets/cmake-macros/deployment.cmake
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#! [qt_generate_deploy_script_example]
cmake_minimum_required(VERSION 3.16...3.22)
@@ -17,7 +17,7 @@ install(TARGETS MyApp
qt_generate_deploy_script(
TARGET MyApp
- FILENAME_VARIABLE deploy_script
+ OUTPUT_SCRIPT deploy_script
CONTENT "
qt_deploy_runtime_dependencies(
EXECUTABLE $<TARGET_FILE_NAME:MyApp>
diff --git a/src/corelib/doc/snippets/cmake-macros/examples.cmake b/src/corelib/doc/snippets/cmake-macros/examples.cmake
index 2ed094cb72..09b7470962 100644
--- a/src/corelib/doc/snippets/cmake-macros/examples.cmake
+++ b/src/corelib/doc/snippets/cmake-macros/examples.cmake
@@ -1,20 +1,46 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#! [qt_wrap_cpp]
+#! [qt_wrap_cpp_1]
set(SOURCES myapp.cpp main.cpp)
qt_wrap_cpp(SOURCES myapp.h)
-add_executable(myapp ${SOURCES})
-#! [qt_wrap_cpp]
+qt_add_executable(myapp ${SOURCES})
+#! [qt_wrap_cpp_1]
+
+#! [qt_wrap_cpp_2]
+set(SOURCES myapp.cpp main.cpp)
+qt_wrap_cpp(SOURCES myapp.h
+ TARGET myapp
+ OPTIONS
+ "$<$<CONFIG:Debug>:-DMY_OPTION_FOR_DEBUG>"
+ "-DDEFINE_CMDLINE_SIGNAL=void cmdlineSignal(const QMap<int, int> &i)"
+ "$<$<CONFIG:Debug>:-DDEFINE_CMDLINE_SIGNAL_IN_GENEX=void cmdlineSignal(const QMap<int$<COMMA> int$<ANGLE-R> &i)>")
+qt_add_executable(myapp ${SOURCES})
+#! [qt_wrap_cpp_2]
+
+#! [qt_wrap_cpp_3]
+set(SOURCES myapp.cpp main.cpp)
+qt_wrap_cpp(SOURCES myapp.h
+ TARGET myapp)
+qt_add_executable(myapp ${SOURCES})
+target_compile_definitions(myapp PRIVATE "$<$<CONFIG:Debug>:MY_OPTION_FOR_DEBUG>"
+ "DEFINE_CMDLINE_SIGNAL=void cmdlineSignal(const QMap<int, int> &i)"
+ "$<$<BOOL:TRUE>:DEFINE_CMDLINE_SIGNAL_IN_GENEX=void cmdlineSignal(const QMap<int$<COMMA> int$<ANGLE-R> &i)>")
+#! [qt_wrap_cpp_3]
+
+#! [qt_wrap_cpp_4]
+qt_add_executable(myapp myapp.cpp main.cpp)
+qt_wrap_cpp("" myapp.cpp TARGET myapp)
+#! [qt_wrap_cpp_4]
#! [qt_add_resources]
set(SOURCES main.cpp)
qt_add_resources(SOURCES example.qrc)
-add_executable(myapp ${SOURCES})
+qt_add_executable(myapp ${SOURCES})
#! [qt_add_resources]
#! [qt_add_resources_target]
-add_executable(myapp main.cpp)
+qt_add_executable(myapp main.cpp)
qt_add_resources(myapp "images"
PREFIX "/images"
FILES image1.png image2.png)
@@ -28,7 +54,7 @@ qt_add_big_resources(SOURCES big_resource.qrc)
list(APPEND SOURCES big_resource.qrc)
set_property(SOURCE big_resource.qrc PROPERTY SKIP_AUTORCC ON)
-add_executable(myapp ${SOURCES})
+qt_add_executable(myapp ${SOURCES})
#! [qt_add_big_resources]
#! [qt_add_binary_resources]
@@ -41,7 +67,7 @@ qt_generate_moc(main.cpp main.moc TARGET myapp)
#! [qt_generate_moc]
#! [qt_import_plugins]
-add_executable(myapp main.cpp)
+qt_add_executable(myapp main.cpp)
target_link_libraries(myapp Qt::Gui Qt::Sql)
qt_import_plugins(myapp
INCLUDE Qt::QCocoaIntegrationPlugin
diff --git a/src/corelib/doc/snippets/cmake-macros/examples.cpp b/src/corelib/doc/snippets/cmake-macros/examples.cpp
new file mode 100644
index 0000000000..b17fcd8e77
--- /dev/null
+++ b/src/corelib/doc/snippets/cmake-macros/examples.cpp
@@ -0,0 +1,16 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [qt_wrap_cpp_4]
+// myapp.cpp
+#include "myapp.h"
+#include <QObject>
+
+class MyApp : public QObject {
+ Q_OBJECT
+public:
+ MyApp() = default;
+};
+
+#include "myapp.moc"
+//! [qt_wrap_cpp_4]
diff --git a/src/corelib/doc/snippets/code/doc_src_containers.cpp b/src/corelib/doc/snippets/code/doc_src_containers.cpp
index 29d9b584d0..b568462492 100644
--- a/src/corelib/doc/snippets/code/doc_src_containers.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_containers.cpp
@@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
+
//! [0]
class Employee
{
@@ -226,13 +228,6 @@ foreach (const QString &str, map.uniqueKeys()) {
//! [20]
-//! [21]
-forever {
- ...
-}
-//! [21]
-
-
//! [22]
CONFIG += no_keywords
//! [22]
@@ -247,9 +242,9 @@ target_compile_definitions(my_app PRIVATE QT_NO_KEYWORDS)
QString onlyLetters(const QString &in)
{
QString out;
- for (int j = 0; j < in.size(); ++j) {
- if (in[j].isLetter())
- out += in[j];
+ for (qsizetype j = 0; j < in.size(); ++j) {
+ if (in.at(j).isLetter())
+ out += in.at(j);
}
return out;
}
@@ -286,15 +281,15 @@ int j = *i; // Undefined behavior!
//! [24]
//! [25]
-QList<int> list { 1, 2, 3, 4, 4, 5 };
-QSet<int> set(list.begin(), list.end());
+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 };
+QList<int> list = {2, 3, 1};
std::sort(list.begin(), list.end());
/*
diff --git a/src/corelib/doc/snippets/code/doc_src_properties.cpp b/src/corelib/doc/snippets/code/doc_src_properties.cpp
index bb369e6456..190a843710 100644
--- a/src/corelib/doc/snippets/code/doc_src_properties.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_properties.cpp
@@ -68,6 +68,9 @@ public:
void setPriority(Priority priority)
{
+ if (m_priority == priority)
+ return;
+
m_priority = priority;
emit priorityChanged(priority);
}
@@ -93,7 +96,7 @@ object->setProperty("priority", "VeryHigh");
//! [7]
-Q_CLASSINFO("Version", "3.0.0")
+Q_CLASSINFO("DefaultProperty", "content")
//! [7]
//! [8]
diff --git a/src/corelib/doc/snippets/code/doc_src_qalgorithms.cpp b/src/corelib/doc/snippets/code/doc_src_qalgorithms.cpp
index 201517aa2a..f2b94a7416 100644
--- a/src/corelib/doc/snippets/code/doc_src_qalgorithms.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_qalgorithms.cpp
@@ -1,15 +1,6 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [0]
-double pi = 3.14;
-double e = 2.71;
-
-qSwap(pi, e);
-// pi == 2.71, e == 3.14
-//! [0]
-
-
//! [1]
QList<Employee *> list;
list.append(new Employee("Blackpool", "Stephen"));
diff --git a/src/corelib/doc/snippets/code/doc_src_qiterator.cpp b/src/corelib/doc/snippets/code/doc_src_qiterator.cpp
index f033a7e1bb..0d921b87e6 100644
--- a/src/corelib/doc/snippets/code/doc_src_qiterator.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_qiterator.cpp
@@ -25,15 +25,6 @@ while (i.hasNext())
float f = i.next();
//! [6]
-
-//! [7]
-QSetIterator<QString> i(set);
-i.toBack();
-while (i.hasPrevious())
- QString s = i.previous();
-//! [7]
-
-
//! [8]
QList<float> list;
...
diff --git a/src/corelib/doc/snippets/code/doc_src_qnamespace.qdoc b/src/corelib/doc/snippets/code/doc_src_qnamespace.qdoc
index 41fc57df40..6ce29308f1 100644
--- a/src/corelib/doc/snippets/code/doc_src_qnamespace.qdoc
+++ b/src/corelib/doc/snippets/code/doc_src_qnamespace.qdoc
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
//! [0]
QObject::connect: Cannot queue arguments of type 'MyType'
diff --git a/src/corelib/doc/snippets/code/doc_src_qplugin.cpp b/src/corelib/doc/snippets/code/doc_src_qplugin.cpp
index 2d6e4a430f..3bca27b966 100644
--- a/src/corelib/doc/snippets/code/doc_src_qplugin.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_qplugin.cpp
@@ -22,9 +22,3 @@ class MyInstance : public QObject
//! [2]
Q_IMPORT_PLUGIN(qjpeg)
//! [2]
-
-
-//! [3]
-TEMPLATE = app
-QTPLUGIN += qjpeg qgif # image formats
-//! [3]
diff --git a/src/corelib/doc/snippets/code/doc_src_qset.cpp b/src/corelib/doc/snippets/code/doc_src_qset.cpp
index 64e0b6e450..98a6f336f5 100644
--- a/src/corelib/doc/snippets/code/doc_src_qset.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_qset.cpp
@@ -34,18 +34,15 @@ while (i.hasNext()) {
//! [5]
-QSet<QWidget *>::const_iterator i = set.constBegin();
-while (i != set.constEnd()) {
+for (auto i = set.cbegin(), end = set.cend(); i != end; ++i)
qDebug() << *i;
- ++i;
-}
//! [5]
//! [6]
QSet<QString> set;
...
-foreach (const QString &value, set)
+for (const auto &value : set)
qDebug() << value;
//! [6]
@@ -59,20 +56,18 @@ for (int i = 0; i < 20000; ++i)
//! [8]
-QSet<QString> set;
-set << "January" << "February" << ... << "December";
+QSet<QString> set = {"January", "February", ... "December"}
-QSet<QString>::iterator i;
-for (i = set.begin(); i != set.end(); ++i)
+// i is a QSet<QString>::iterator
+for (auto i = set.begin(), end = set.end(); i != end; ++i)
qDebug() << *i;
//! [8]
//! [9]
-QSet<QString> set;
-set << "January" << "February" << ... << "December";
+QSet<QString> set = {"January", "February", ... "December"};
-QSet<QString>::iterator i = set.begin();
+auto i = set.begin();
while (i != set.end()) {
if ((*i).startsWith('J')) {
i = set.erase(i);
@@ -94,11 +89,10 @@ if (it != set.end())
//! [11]
-QSet<QString> set;
-set << "January" << "February" << ... << "December";
+QSet<QString> set = {"January", "February", ... "December"};
-QSet<QString>::const_iterator i;
-for (i = set.begin(); i != set.end(); ++i)
+// i is QSet<QString>::const_iterator
+for (auto i = set.cbegin(), end = set.cend(); i != end; ++i)
qDebug() << *i;
//! [11]
@@ -111,23 +105,3 @@ QSet<QString>::const_iterator it = std::find_if(set.cbegin(), set.cend(), predic
if (it != set.constEnd())
cout << "Found Jeanette" << endl;
//! [12]
-
-
-//! [13]
-QSet<QString> set;
-set << "red" << "green" << "blue" << ... << "black";
-
-QList<QString> list = set.toList();
-std::sort(list.begin(), list.end());
-//! [13]
-
-
-//! [14]
-QStringList list;
-list << "Julia" << "Mike" << "Mike" << "Julia" << "Julia";
-
-QSet<QString> set = QSet<QString>::fromList(list);
-set.contains("Julia"); // returns true
-set.contains("Mike"); // returns true
-set.size(); // returns 2
-//! [14]
diff --git a/src/corelib/doc/snippets/code/doc_src_resources.cpp b/src/corelib/doc/snippets/code/doc_src_resources.cpp
index 5df085d145..04ecf810ec 100644
--- a/src/corelib/doc/snippets/code/doc_src_resources.cpp
+++ b/src/corelib/doc/snippets/code/doc_src_resources.cpp
@@ -15,16 +15,3 @@ MyClass::MyClass() : BaseClass()
...
}
//! [5]
-
-
-//! [6]
-int main(int argc, char *argv[])
-{
- QApplication app(argc, argv);
- Q_INIT_RESOURCE(graphlib);
-
- QFile file(":/graph.png");
- ...
- return app.exec();
-}
-//! [6]
diff --git a/src/corelib/doc/snippets/code/doc_src_resources.qdoc b/src/corelib/doc/snippets/code/doc_src_resources.qdoc
index a2e515ce03..70c2a7b7ab 100644
--- a/src/corelib/doc/snippets/code/doc_src_resources.qdoc
+++ b/src/corelib/doc/snippets/code/doc_src_resources.qdoc
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
//! [0]
<file alias="cut-img.png">images/cut.png</file>
@@ -26,3 +26,7 @@
//! [3]
rcc -binary myresource.qrc -o myresource.rcc
//! [3]
+
+//! [4]
+<file empty="true">Button.qml</file>
+//! [4]
diff --git a/src/corelib/doc/snippets/code/qlogging/qlogging.cpp b/src/corelib/doc/snippets/code/qlogging/qlogging.cpp
index d1c3c7b00d..e61eb70df3 100644
--- a/src/corelib/doc/snippets/code/qlogging/qlogging.cpp
+++ b/src/corelib/doc/snippets/code/qlogging/qlogging.cpp
@@ -1,14 +1,16 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
+
#include <QtGui>
#include <QtDebug>
-#include <QDeclarativeComponent>
+#include <QQmlComponent>
//! [1]
- void statusChanged(QDeclarativeComponent::Status status) {
- if (status == QDeclarativeComponent::Error) {
- foreach (const QDeclarativeError &error, component->errors()) {
+ void statusChanged(QQmlComponent::Status status) {
+ if (status == QQmlComponent::Error) {
+ for (const QQmlError &error: std::as_const(component->errors())) {
const QByteArray file = error.url().toEncoded();
QMessageLogger(file.constData(), error.line(), 0).debug() << error.description();
}
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 f8b74cd542..4b77ab607d 100644
--- a/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_animation_qpropertyanimation.cpp
@@ -6,7 +6,7 @@
#include <QApplication>
#include <QPushButton>
#include <QPropertyAnimation>
-//! [1]
+
class MyButtonWidget : public QWidget
{
public:
@@ -31,7 +31,6 @@ int main(int argc, char *argv[])
buttonAnimWidget.show();
return a.exec();
}
-//! [1]
//! [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 096e36dc72..25d3abf67e 100644
--- a/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_global_qglobal.cpp
@@ -32,17 +32,6 @@ Q_FLAG(Options)
typedef QFlags<Enum> Flags;
//! [2]
-
-//! [3]
-int myValue = 10;
-int minValue = 2;
-int maxValue = 6;
-
-int boundedValue = qBound(minValue, myValue, maxValue);
-// boundedValue == 6
-//! [3]
-
-
//! [4]
if (!driver()->isOpen() || driver()->isOpenError()) {
qWarning("QSqlQuery::exec: database not open");
@@ -61,11 +50,6 @@ quint64 value = Q_UINT64_C(932838457459459);
//! [6]
-//! [7]
-void myMsgHandler(QtMsgType, const char *);
-//! [7]
-
-
//! [8]
qint64 value = Q_INT64_C(932838457459459);
//! [8]
@@ -226,37 +210,26 @@ const TInputType &myMin(const TInputType &value1, const TInputType &value2)
//! [23]
-#include <qapplication.h>
+#include <QApplication>
#include <stdio.h>
#include <stdlib.h>
-void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
+QtMessageHandler originalHandler = nullptr;
+
+void logToFile(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
- QByteArray localMsg = msg.toLocal8Bit();
- const char *file = context.file ? context.file : "";
- const char *function = context.function ? context.function : "";
- switch (type) {
- case QtDebugMsg:
- fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
- break;
- case QtInfoMsg:
- fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
- break;
- case QtWarningMsg:
- fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
- break;
- case QtCriticalMsg:
- fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
- break;
- case QtFatalMsg:
- fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), file, context.line, function);
- break;
- }
+ QString message = qFormatLogMessage(type, context, msg);
+ static FILE *f = fopen("log.txt", "a");
+ fprintf(f, "%s\n", qPrintable(message));
+ fflush(f);
+
+ if (originalHandler)
+ *originalHandler(type, context, msg);
}
int main(int argc, char **argv)
{
- qInstallMessageHandler(myMessageOutput);
+ originalHandler = qInstallMessageHandler(logToFile);
QApplication app(argc, argv);
...
return app.exec();
@@ -579,11 +552,6 @@ qFuzzyCompare(0.0, 1.0e-200); // This will return false
qFuzzyCompare(1 + 0.0, 1 + 1.0e-200); // This will return true
//! [46]
-//! [47]
-CApaApplication *myApplicationFactory();
-//! [47]
-
-
//! [49]
void myMessageHandler(QtMsgType, const QMessageLogContext &, const QString &);
//! [49]
@@ -667,19 +635,6 @@ bool readConfiguration(const QFile &file)
}
//! [qunreachable-switch]
-//! [qunreachable-return]
- switch (shape) {
- case Rectangle:
- return rectangle();
- case Triangle:
- return triangle();
- case Circle:
- return circle();
- case NumShapes:
- Q_UNREACHABLE_RETURN(nullptr);
- }
-//! [qunreachable-return]
-
//! [qt-version-check]
#include <QtGlobal>
diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qabstractfileengine.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qabstractfileengine.cpp
index 8c80ec1eba..4300fc2da9 100644
--- a/src/corelib/doc/snippets/code/src_corelib_io_qabstractfileengine.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_io_qabstractfileengine.cpp
@@ -1,17 +1,21 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+using namespace Qt::StringLiterals;
+
//! [0]
class ZipEngineHandler : public QAbstractFileEngineHandler
{
public:
- QAbstractFileEngine *create(const QString &fileName) const override;
+ std::unique_ptr<QAbstractFileEngine> create(const QString &fileName) const override;
};
-QAbstractFileEngine *ZipEngineHandler::create(const QString &fileName) const
+std::unique_ptr<QAbstractFileEngine> ZipEngineHandler::create(const QString &fileName) const
{
// ZipEngineHandler returns a ZipEngine for all .zip files
- return fileName.toLower().endsWith(".zip") ? new ZipEngine(fileName) : 0;
+ if (fileName.toLower().endsWith(".zip"_L1))
+ return std::make_unique<ZipEngine>(fileName);
+ return {};
}
int main(int argc, char **argv)
@@ -27,21 +31,24 @@ int main(int argc, char **argv)
}
//! [0]
-
//! [1]
-QAbstractSocketEngine *ZipEngineHandler::create(const QString &fileName) const
+std::unique_ptr<QAbstractFileEngine> ZipEngineHandler::create(const QString &fileName) const
{
// ZipEngineHandler returns a ZipEngine for all .zip files
- return fileName.toLower().endsWith(".zip") ? new ZipEngine(fileName) : 0;
+ if (fileName.toLower().endsWith(".zip"_L1))
+ return std::make_unique<ZipEngine>(fileName);
+ else
+ return {};
}
//! [1]
//! [2]
-QAbstractFileEngineIterator *
-CustomFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filterNames)
+QAbstractFileEngine::IteratorUniquePtr
+CustomFileEngine::beginEntryList(const QString &path, QDir::Filters filters,
+ const QStringList &filterNames)
{
- return new CustomFileEngineIterator(filters, filterNames);
+ return std::make_unique<CustomFileEngineIterator>(path, filters, filterNames);
}
//! [2]
@@ -50,25 +57,23 @@ CustomFileEngine::beginEntryList(QDir::Filters filters, const QStringList &filte
class CustomIterator : public QAbstractFileEngineIterator
{
public:
- CustomIterator(const QStringList &nameFilters, QDir::Filters filters)
- : QAbstractFileEngineIterator(nameFilters, filters), index(0)
+ CustomIterator(const QString &path, const QStringList &nameFilters, QDir::Filters filters)
+ : QAbstractFileEngineIterator(path, nameFilters, filters), index(0)
{
// In a real iterator, these entries are fetched from the
// file system based on the value of path().
entries << "entry1" << "entry2" << "entry3";
}
- bool hasNext() const override
- {
- return index < entries.size() - 1;
- }
-
- QString next() override
+ bool advance() override
{
- if (!hasNext())
- return QString();
- ++index;
- return currentFilePath();
+ if (entries.isEmpty())
+ return false;
+ if (index < entries.size() - 1) {
+ ++index;
+ return true;
+ }
+ return false;
}
QString currentFileName() override
diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qdirlisting.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qdirlisting.cpp
new file mode 100644
index 0000000000..231bf48d26
--- /dev/null
+++ b/src/corelib/doc/snippets/code/src_corelib_io_qdirlisting.cpp
@@ -0,0 +1,70 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include <QDirListing>
+
+using namespace Qt::StringLiterals;
+
+[[maybe_unused]] static void func() {
+{
+//! [0]
+using ItFlag = QDirListing::IteratorFlag;
+for (const auto &dirEntry : QDirListing(u"/etc"_s, ItFlag::Recursive)) {
+ qDebug() << dirEntry.filePath();
+ // /etc/.
+ // /etc/..
+ // /etc/X11
+ // /etc/X11/fs
+ // ...
+}
+//! [0]
+}
+
+{
+//! [1]
+using ItFlag = QDirListing::IteratorFlag;
+QDirListing dirList(u"/sys"_s, QStringList{u"scaling_cur_freq"_s},
+ QDir::NoFilter, ItFlag::Recursive);
+for (const auto &dirEntry : dirList) {
+ QFile f(dirEntry.filePath());
+ f.open(QIODevice::ReadOnly);
+ qDebug() << f.fileName() << f.readAll().trimmed().toDouble() / 1000 << "MHz";
+}
+//! [1]
+}
+
+{
+//! [2]
+QDirListing audioFileIt(u"/home/johndoe/"_s, {"*.mp3", "*.wav"}, QDir::Files);
+//! [2]
+}
+
+{
+//! [3]
+using ItFlag = QDirListing::IteratorFlag;
+for (const auto &dirEntry : QDirListing(u"/etc"_s, ItFlag::Recursive)) {
+ // Faster
+ if (dirEntry.fileName().endsWith(u".conf")) { /* ... */ }
+
+ // This works, but might be potentially slower, since it has to construct a
+ // QFileInfo, whereas (depending on the implemnetation) the fileName could
+ // be known already
+ if (dirEntry.fileInfo().fileName().endsWith(u".conf")) { /* ... */ }
+}
+//! [3]
+}
+
+{
+//! [4]
+using ItFlag = QDirListing::IteratorFlag;
+for (const auto &dirEntry : QDirListing(u"/etc"_s, ItFlag::Recursive)) {
+ // Both approaches are the same, because DirEntry will have to construct
+ // a QFileInfo to get this info (for example, by calling system stat())
+
+ if (dirEntry.size() >= 4'000 /* 4KB */) { /* ...*/ }
+ if (dirEntry.fileInfo().size() >= 4'000 /* 4KB */) { /* ... */ }
+}
+//! [4]
+}
+
+}
diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qfile.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qfile.cpp
index 475bc874ec..3a8f7d2747 100644
--- a/src/corelib/doc/snippets/code/src_corelib_io_qfile.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_io_qfile.cpp
@@ -10,16 +10,6 @@ file.open(QIODevice::ReadOnly); // opens "/home/readme.txt" under Unix
//! [0]
-//! [1]
-QByteArray myEncoderFunc(const QString &fileName);
-//! [1]
-
-
-//! [2]
-QString myDecoderFunc(const QByteArray &localFileName);
-//! [2]
-
-
//! [3]
#include <stdio.h>
diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qfileinfo.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qfileinfo.cpp
index 9e548afafc..a8dd621111 100644
--- a/src/corelib/doc/snippets/code/src_corelib_io_qfileinfo.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_io_qfileinfo.cpp
@@ -1,11 +1,21 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QDir>
+#include <QFileInfo>
+using namespace Qt::StringLiterals;
+
+[[maybe_unused]] static void func()
+{
+{
//![newstuff]
- QFileInfo fi("c:/temp/foo"); => fi.absoluteFilePath() => "C:/temp/foo"
+ QFileInfo fi("c:/temp/foo");
+ qDebug() << fi.absoluteFilePath(); // "C:/temp/foo"
//![newstuff]
+}
+{
//! [0]
#ifdef Q_OS_UNIX
@@ -22,7 +32,7 @@ info2.size(); // returns 56201
#endif
//! [0]
-
+}
//! [1]
#ifdef Q_OS_WIN
@@ -41,7 +51,7 @@ info2.size(); // returns 63942
#endif
//! [1]
-
+{
//! [2]
QFileInfo info("/usr/bin/env");
@@ -53,50 +63,60 @@ info.setFile("/etc/hosts");
path = info.absolutePath(); // path = /etc
base = info.baseName(); // base = hosts
//! [2]
+}
+{
//! [3]
QFileInfo fi("/tmp/archive.tar.gz");
QString name = fi.fileName(); // name = "archive.tar.gz"
//! [3]
+}
-
+{
//! [4]
QFileInfo fi("/Applications/Safari.app");
QString bundle = fi.bundleName(); // name = "Safari"
//! [4]
+}
-
+{
//! [5]
QFileInfo fi("/tmp/archive.tar.gz");
QString base = fi.baseName(); // base = "archive"
//! [5]
+}
-
+{
//! [6]
QFileInfo fi("/tmp/archive.tar.gz");
QString base = fi.completeBaseName(); // base = "archive.tar"
//! [6]
+}
-
+{
//! [7]
QFileInfo fi("/tmp/archive.tar.gz");
QString ext = fi.completeSuffix(); // ext = "tar.gz"
//! [7]
+}
-
+{
//! [8]
QFileInfo fi("/tmp/archive.tar.gz");
QString ext = fi.suffix(); // ext = "gz"
//! [8]
+}
-
+{
+QString fileName = "foo";
//! [9]
QFileInfo info(fileName);
if (info.isSymLink())
fileName = info.symLinkTarget();
//! [9]
+}
-
+{
//! [10]
QFileInfo fi("/tmp/archive.tar.gz");
if (fi.permission(QFile::WriteUser | QFile::ReadGroup))
@@ -104,3 +124,24 @@ if (fi.permission(QFile::WriteUser | QFile::ReadGroup))
if (fi.permission(QFile::WriteGroup | QFile::WriteOther))
qWarning("The group or others can change the file");
//! [10]
+}
+
+{
+//! [11]
+// Given a current working directory of "/home/user/Documents/memos/"
+QFileInfo info1(u"relativeFile"_s);
+qDebug() << info1.absolutePath(); // "/home/user/Documents/memos/"
+qDebug() << info1.baseName(); // "relativeFile"
+qDebug() << info1.absoluteDir(); // QDir(u"/home/user/Documents/memos"_s)
+qDebug() << info1.absoluteDir().path(); // "/home/user/Documents/memos"
+
+// A QFileInfo on a dir
+QFileInfo info2(u"/home/user/Documents/memos"_s);
+qDebug() << info2.absolutePath(); // "/home/user/Documents"
+qDebug() << info2.baseName(); // "memos"
+qDebug() << info2.absoluteDir(); // QDir(u"/home/user/Documents"_s)
+qDebug() << info2.absoluteDir().path(); // "/home/user/Documents"
+//! [11]
+}
+
+}
diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qsettings.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qsettings.cpp
index cc93e32d05..5774add2a7 100644
--- a/src/corelib/doc/snippets/code/src_corelib_io_qsettings.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_io_qsettings.cpp
@@ -45,7 +45,7 @@ settings.value("HKEY_CURRENT_USER\\MySoft\\Star Runner\\Galaxy\\Default"); // re
//! [7]
-#ifdef Q_OS_MAC
+#ifdef Q_OS_DARWIN
QSettings settings("grenoullelogique.fr", "Squash");
#else
QSettings settings("Grenoulle Logique", "Squash");
@@ -138,10 +138,10 @@ QList<Login> logins;
QSettings settings;
settings.beginWriteArray("logins");
-for (int i = 0; i < logins.size(); ++i) {
+for (qsizetype i = 0; i < logins.size(); ++i) {
settings.setArrayIndex(i);
- settings.setValue("userName", list.at(i).userName);
- settings.setValue("password", list.at(i).password);
+ settings.setValue("userName", logins.at(i).userName);
+ settings.setValue("password", logins.at(i).password);
}
settings.endArray();
//! [16]
diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qstorageinfo.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qstorageinfo.cpp
index d11368a83d..93029274b1 100644
--- a/src/corelib/doc/snippets/code/src_corelib_io_qstorageinfo.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_io_qstorageinfo.cpp
@@ -1,6 +1,8 @@
// Copyright (C) 2014 Ivan Komissarov
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
+
//! [0]
QStorageInfo storage(qApp->applicationDirPath());
if (storage.isValid() && storage.isReady()) {
diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp
index bcc08c0f16..75a04e654f 100644
--- a/src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_io_qtextstream.cpp
@@ -84,9 +84,3 @@ out << "Qt rocks!" << Qt::endl;
//! [9]
stream << '\n' << Qt::flush;
//! [9]
-
-
-//! [10]
-QTextStream out(&file);
-out.setEncoding(QStringConverter::Utf8);
-//! [10]
diff --git a/src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp b/src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp
index 62ecc58a80..945f3ae3e7 100644
--- a/src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_io_qurl.cpp
@@ -1,6 +1,14 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+//! [constructor-url-reference]
+QUrl url("example.com");
+//! [constructor-url-reference]
+
+//! [constructor-url]
+QUrl url("https://example.com");
+//! [constructor-url]
+
//! [0]
QUrl url("http://www.example.com/List of holidays.xml");
// url.toEncoded() == "http://www.example.com/List%20of%20holidays.xml"
@@ -31,7 +39,7 @@ sock.connectToHost(url.host(), url.port(80));
//! [4]
-http://www.example.com/cgi-bin/drawgraph.cgi?type(pie)color(green)
+http://www.example.com/cgi-bin/drawgraph.cgi?type,pie;color,green
//! [4]
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp
index 3f7dc07d9f..4fd7f97ae8 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qabstractitemmodel.cpp
@@ -50,16 +50,6 @@ beginMoveRows(parent, 2, 2, parent, 0);
beginMoveRows(parent, 2, 2, parent, 4);
//! [9]
-//! [10]
-myData.clear();
-reset();
-//! [10]
-
-//! [11]
-beginResetModel();
-myData.clear();
-endResetModel();
-//! [11]
//! [12]
class CustomDataProxy : public QSortFilterProxyModel
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp
index 2a3a27e94b..8087ff8f8b 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qcoreapplication.cpp
@@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
+
//! [0]
QMouseEvent event(QEvent::MouseButtonPress, pos, 0, 0, 0);
QApplication::sendEvent(mainWindow, &event);
@@ -13,12 +15,6 @@ connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::Qu
//! [1]
-//! [2]
-foreach (const QString &path, app.libraryPaths())
- do_something(path);
-//! [2]
-
-
//! [3]
// Called once QCoreApplication exists
static void preRoutineMyDebugTool()
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qdeadlinetimer.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qdeadlinetimer.cpp
index a3b366a588..f7440f2bb0 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qdeadlinetimer.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qdeadlinetimer.cpp
@@ -63,25 +63,25 @@
//! [7]
//! [8]
- return d1.deadlineNSecs() == d2.deadlineNSecs();
+ return lhs.deadlineNSecs() == rhs.deadlineNSecs();
//! [8]
//! [9]
- return d1.deadlineNSecs() != d2.deadlineNSecs();
+ return lhs.deadlineNSecs() != rhs.deadlineNSecs();
//! [9]
//! [10]
- return d1.deadlineNSecs() < d2.deadlineNSecs();
+ return lhs.deadlineNSecs() < rhs.deadlineNSecs();
//! [10]
//! [11]
- return d1.deadlineNSecs() <= d2.deadlineNSecs();
+ return lhs.deadlineNSecs() <= rhs.deadlineNSecs();
//! [11]
//! [12]
- return d1.deadlineNSecs() > d2.deadlineNSecs();
+ return lhs.deadlineNSecs() > rhs.deadlineNSecs();
//! [12]
//! [13]
- return d1.deadlineNSecs() >= d2.deadlineNSecs();
+ return lhs.deadlineNSecs() >= rhs.deadlineNSecs();
//! [13]
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp
index a213ccbca6..757700786e 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qmetatype.cpp
@@ -101,16 +101,6 @@ void someFunc()
//! [11]
-//! [12]
-QPointer<QFile> fp(new QFile);
-QVariant var = QVariant::fromValue(fp);
-// ...
-if (var.canConvert<QObject*>()) {
- QObject *sp = var.value<QObject*>();
- qDebug() << sp->metaObject()->className(); // Prints 'QFile'.
-}
-//! [12]
-
//! [13]
#include <memory>
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qmimedata.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qmimedata.cpp
index 36cbdefa1c..c6a48c8827 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qmimedata.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qmimedata.cpp
@@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
+
//! [0]
void MyWidget::dragEnterEvent(QDragEnterEvent *event)
{
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp
index 2c5483abce..e3bbac7a3c 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qobject.cpp
@@ -129,13 +129,6 @@ void MyObject::timerEvent(QTimerEvent *event)
//! [8]
-//! [9]
-QList<QObject *> list = window()->queryList("QAbstractButton"));
-foreach (QObject *obj, list)
- static_cast<QAbstractButton *>(obj)->setEnabled(false);
-//! [9]
-
-
//! [10]
QPushButton *button = parentWidget->findChild<QPushButton *>("button1");
//! [10]
@@ -204,22 +197,6 @@ MyWindow::MyWindow()
}
-//! [18]
-int n = messages.count();
-showMessage(tr("%n message(s) saved", "", n));
-//! [18]
-
-
-//! [19]
-n == 1 ? tr("%n message saved") : tr("%n messages saved")
-//! [19]
-
-
-//! [20]
-label->setText(tr("F\374r \310lise"));
-//! [20]
-
-
//! [21]
if (receivers(SIGNAL(valueChanged(QByteArray))) > 0) {
QByteArray data;
@@ -383,21 +360,13 @@ public:
//! [39]
-//! [40]
-//: This name refers to a host name.
-hostNameLabel->setText(tr("Name:"));
-
-/*: This text refers to a C++ code example. */
-QString example = tr("Example");
-//! [40]
-
//! [41]
QPushButton *button = parentWidget->findChild<QPushButton *>("button1", Qt::FindDirectChildrenOnly);
//! [41]
//! [42]
-QListWidget *list = parentWidget->findChild<QListWidget *>(QString(), Qt::FindDirectChildrenOnly);
+QListWidget *list = parentWidget->findChild<QListWidget *>(Qt::FindDirectChildrenOnly);
//! [42]
@@ -487,18 +456,6 @@ public:
};
//! [52]
-//! [meta data]
-//: This is a comment for the translator.
-//= qtn_foo_bar
-//~ loc-layout_id foo_dialog
-//~ loc-blank False
-//~ magic-stuff This might mean something magic.
-QString text = MyMagicClass::tr("Sim sala bim.");
-//! [meta data]
-
-//! [explicit tr context]
-QString text = QScrollBar::tr("Page up");
-//! [explicit tr context]
//! [53]
{
@@ -512,3 +469,16 @@ const bool wasBlocked = someQObject->blockSignals(true);
// no signals here
someQObject->blockSignals(wasBlocked);
//! [54]
+
+{
+//! [invalid-timer-id]
+ QObject *obj;
+ ...
+ int id = obj->startTimer(100ms);
+ if (id > Qt::TimerId::Invalid)
+ // The timer has been started successfully
+
+ if (id > 0) // Equivalent, albeit less readable
+ // The timer has been started successfully
+//! [invalid-timer-id]
+}
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp
index f4cc826e6f..c2b55c9684 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qproperty.cpp
@@ -144,7 +144,7 @@ public:
Q_D(MyClass);
d->clients.push_back(c);
// notify that the value could have changed
- d->hasClientsData.markDirty();
+ d->hasClientsData.notify();
}
private:
Q_DECLARE_PRIVATE(MyClass)
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp
index d1afba270e..45da88c75d 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qsystemsemaphore.cpp
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
//! [0]
-QSystemSemaphore sem("market", 3, QSystemSemaphore::Create);
+QSystemSemaphore sem(QSystemSemaphore::platformSafeKey("market"), 3, QSystemSemaphore::Create);
// resources available == 3
sem.acquire(); // resources available == 2
sem.acquire(); // resources available == 1
@@ -13,7 +13,7 @@ sem.release(2); // resources available == 3
//! [1]
-QSystemSemaphore sem("market", 5, QSystemSemaphore::Create);
+QSystemSemaphore sem(QSystemSemaphore::platformSafeKey("market"), 5, QSystemSemaphore::Create);
for (int i = 0; i < 5; ++i) // acquire all 5 resources
sem.acquire();
sem.release(5); // release the 5 resources
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qtimer.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qtimer.cpp
index 7dfd17a1f1..5edcaae755 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qtimer.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qtimer.cpp
@@ -8,7 +8,7 @@
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
- QTimer::singleShot(600000, &app, SLOT(quit()));
+ QTimer::singleShot(600000, &app, QCoreApplication::quit);
...
return app.exec();
}
diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp
index e0c846a587..7f3f1ce7a0 100644
--- a/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp
@@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
+
//! [0]
QDataStream out(...);
QVariant v(123); // The variant now contains an int
@@ -89,11 +91,6 @@ return QVariant::fromValue(s);
//! [7]
-//! [8]
-QObject *object = getObjectFromSomewhere();
-QVariant data = QVariant::fromValue(object);
-//! [8]
-
//! [9]
QList<int> intList = {7, 11, 42};
diff --git a/src/corelib/doc/snippets/code/src_corelib_serialization_qcborstream.cpp b/src/corelib/doc/snippets/code/src_corelib_serialization_qcborstream.cpp
index 90f89d8bd1..acb5a6272e 100644
--- a/src/corelib/doc/snippets/code/src_corelib_serialization_qcborstream.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_serialization_qcborstream.cpp
@@ -183,7 +183,7 @@ using namespace Qt::StringLiterals;
//! [21]
//! [22]
- void appendMap(QCborStreamWriter &writer, const QList<QPair<int, QString>> &values)
+ void appendMap(QCborStreamWriter &writer, const QList<std::pair<int, QString>> &values)
{
writer.startMap();
for (const auto pair : values) {
@@ -198,7 +198,7 @@ using namespace Qt::StringLiterals;
void appendMap(QCborStreamWriter &writer, const QMap<int, QString> &map)
{
writer.startMap(map.size());
- for (auto it = map.begin(); it != map.end(); ++it) {
+ for (auto it = map.cbegin(), end = map.cend(); it != end; ++it) {
writer.append(it.key());
writer.append(it.value());
}
@@ -271,12 +271,12 @@ using namespace Qt::StringLiterals;
{
QString result;
auto r = reader.readString();
- while (r.code == QCborStreamReader::Ok) {
+ while (r.status == QCborStreamReader::Ok) {
result += r.data;
r = reader.readString();
}
- if (r.code == QCborStreamReader::Error) {
+ if (r.status == QCborStreamReader::Error) {
// handle error condition
result.clear();
}
@@ -289,12 +289,12 @@ using namespace Qt::StringLiterals;
{
QBytearray result;
auto r = reader.readBytearray();
- while (r.code == QCborStreamReader::Ok) {
+ while (r.status == QCborStreamReader::Ok) {
result += r.data;
r = reader.readByteArray();
}
- if (r.code == QCborStreamReader::Error) {
+ if (r.status == QCborStreamReader::Error) {
// handle error condition
result.clear();
}
diff --git a/src/corelib/doc/snippets/code/src_corelib_serialization_qdatastream.cpp b/src/corelib/doc/snippets/code/src_corelib_serialization_qdatastream.cpp
index 296a341b11..dfdebe6a76 100644
--- a/src/corelib/doc/snippets/code/src_corelib_serialization_qdatastream.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_serialization_qdatastream.cpp
@@ -2,11 +2,11 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
//! [0]
- QDataStream &operator<<(QDataStream &, const QXxx &);
- QDataStream &operator>>(QDataStream &, QXxx &);
+QDataStream &operator<<(QDataStream &, const QXxx &);
+QDataStream &operator>>(QDataStream &, QXxx &);
//! [0]
//! [1]
- QDataStream & operator<< (QDataStream& stream, const QImage& image);
- QDataStream & operator>> (QDataStream& stream, QImage& image);
+QDataStream &operator<<(QDataStream &stream, const QImage &image);
+QDataStream &operator>>(QDataStream &stream, QImage &image);
//! [1]
diff --git a/src/corelib/doc/snippets/code/src_corelib_text_qbytearray.cpp b/src/corelib/doc/snippets/code/src_corelib_text_qbytearray.cpp
index 8a9cb7c841..a4fecc41f9 100644
--- a/src/corelib/doc/snippets/code/src_corelib_text_qbytearray.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_text_qbytearray.cpp
@@ -24,7 +24,7 @@ ba[4] = 0xca;
//! [2]
for (qsizetype i = 0; i < ba.size(); ++i) {
if (ba.at(i) >= 'a' && ba.at(i) <= 'f')
- cout << "Found character in range [a-f]" << Qt::endl;
+ cout << "Found character in range [a-f]" << endl;
}
//! [2]
@@ -41,7 +41,7 @@ x.replace(5, 3, "&"); // x == "rock & roll"
QByteArray ba("We must be <b>bold</b>, very <b>bold</b>");
qsizetype j = 0;
while ((j = ba.indexOf("<b>", j)) != -1) {
- cout << "Found <b> tag at index position " << j << Qt::endl;
+ cout << "Found <b> tag at index position " << j << endl;
++j;
}
//! [4]
@@ -79,7 +79,7 @@ QByteArray("abc").isEmpty(); // returns false
QByteArray ba("Hello world");
char *data = ba.data();
while (*data) {
- cout << "[" << *data << "]" << Qt::endl;
+ cout << "[" << *data << "]" << endl;
++data;
}
//! [8]
@@ -461,4 +461,21 @@ QByteArray ba = QByteArrayLiteral("byte array contents");
QByteArray encoded("Qt%20is%20great%33");
QByteArray decoded = encoded.percentDecoded(); // Set to "Qt is great!"
//! [54]
+
+//! [55]
+emscripten::val uint8array = emscripten::val::global("g_uint8array");
+QByteArray byteArray = QByteArray::fromEcmaUint8Array(uint8array);
+//! [55]
+
+//! [56]
+QByteArray byteArray = "test";
+emscripten::val uint8array = QByteArray::toEcmaUint8Array(byteArray);
+//! [56]
+
+//! [57]
+QByteArray x = "Five pineapples"_ba;
+x.slice(5); // x == "pineapples"
+x.slice(4, 3); // x == "app"
+//! [57]
+
}
diff --git a/src/corelib/doc/snippets/code/src_corelib_text_qstaticlatin1stringmatcher.cpp b/src/corelib/doc/snippets/code/src_corelib_text_qstaticlatin1stringmatcher.cpp
new file mode 100644
index 0000000000..ae6e19e471
--- /dev/null
+++ b/src/corelib/doc/snippets/code/src_corelib_text_qstaticlatin1stringmatcher.cpp
@@ -0,0 +1,8 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+//! [0]
+static constexpr auto matcher = qMakeStaticCaseSensitiveLatin1StringViewMatcher("needle");
+//! [0]
+//! [1]
+static constexpr auto matcher = qMakeStaticCaseInsensitiveLatin1StringViewMatcher("needle");
+//! [1]
diff --git a/src/corelib/doc/snippets/code/src_corelib_text_qstringconverter.cpp b/src/corelib/doc/snippets/code/src_corelib_text_qstringconverter.cpp
index e7bd39c95c..b5bfc9cd55 100644
--- a/src/corelib/doc/snippets/code/src_corelib_text_qstringconverter.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_text_qstringconverter.cpp
@@ -34,3 +34,27 @@ while (new_data_available()) {
encoded += fromUtf16(chunk);
}
//! [3]
+
+{
+//! [4]
+QByteArray encodedString = "...";
+auto toUtf16 = QStringDecoder(QStringDecoder::Utf8);
+auto data = toUtf16(encodedString); // data's type is QStringDecoder::EncodedData<const QByteArray &>
+QString string = toUtf16(encodedString); // Implicit conversion to QString
+
+// Here you have to cast "data" to QString
+auto func = [&]() { return !toUtf16.hasError() ? QString(data) : u"foo"_s; }
+//! [4]
+}
+
+{
+//! [5]
+QString string = "...";
+auto fromUtf16 = QStringEncoder(QStringEncoder::Utf8);
+auto data = fromUtf16(string); // data's type is QStringEncoder::DecodedData<const QString &>
+QByteArray encodedString = fromUtf16(string); // Implicit conversion to QByteArray
+
+// Here you have to cast "data" to QByteArray
+auto func = [&]() { return !fromUtf16.hasError() ? QByteArray(data) : "foo"_ba; }
+//! [5]
+}
diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp
index 091d98539b..500d7cc7a5 100644
--- a/src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_thread_qfuture.cpp
@@ -6,7 +6,7 @@ QFuture<QString> future = ...;
QFuture<QString>::const_iterator i;
for (i = future.constBegin(); i != future.constEnd(); ++i)
- cout << *i << Qt::endl;
+ cout << qPrintable(*i) << endl;
//! [0]
@@ -239,9 +239,9 @@ auto future = QtConcurrent::run([] {
//! [20]
QObject *context = ...;
-auto future = cachedResultsReady ? QtFuture::makeReadyFuture(results)
- : QtConcurrent::run([] { /* compute results */});
-auto continuation = future.then(context, [] (Results results) {
+auto future = cachedResultsReady ? QtFuture::makeReadyValueFuture(result)
+ : QtConcurrent::run([] { /* compute result */});
+auto continuation = future.then(context, [] (Result result) {
// Runs in the context's thread
}).then([] {
// May or may not run in the context's thread
@@ -385,3 +385,58 @@ QFuture<QFuture<QFuture<int>>>> outerFuture;
QFuture<int> unwrappedFuture = outerFuture.unwrap();
//! [30]
+
+//! [31]
+QPromise<int> p;
+
+QFuture<int> f1 = p.future();
+f1.then([](int) { qDebug("first"); });
+
+QFuture<int> f2 = p.future();
+f2.then([](int) { qDebug("second"); });
+
+p.start();
+p.addResult(42);
+p.finish();
+//! [31]
+
+//! [32]
+const std::vector<int> values{1, 2, 3};
+auto f = QtFuture::makeReadyRangeFuture(values);
+//! [32]
+
+//! [33]
+auto f = QtFuture::makeReadyRangeFuture({1, 2, 3});
+//! [33]
+
+//! [34]
+const int count = f.resultCount(); // count == 3
+const auto results = f.results(); // results == { 1, 2, 3 }
+//! [34]
+
+//! [35]
+auto f = QtFuture::makeReadyValueFuture(std::make_unique<int>(42));
+...
+const int result = *f.takeResult(); // result == 42
+//! [35]
+
+//! [36]
+auto f = QtFuture::makeReadyVoidFuture();
+...
+const bool started = f.isStarted(); // started == true
+const bool running = f.isRunning(); // running == false
+const bool finished = f.isFinished(); // finished == true
+//! [36]
+
+//! [37]
+QObject *context = ...;
+auto future = ...;
+auto continuation = future.then(context, [context](Result result) {
+ // ...
+ }).onCanceled([context = QPointer(context)] {
+ if (!context)
+ return; // context was destroyed already
+ // handle cancellation
+ });
+
+//! [37]
diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qmutexpool.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qmutexpool.cpp
deleted file mode 100644
index 1368559b24..0000000000
--- a/src/corelib/doc/snippets/code/src_corelib_thread_qmutexpool.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-//! [0]
-class Number {
-public:
- Number(double n) : num (n) { }
-
- void setNumber(double n) { num = n; }
- double number() const { return num; }
-
-private:
- double num;
-};
-//! [0]
-
-
-//! [1]
-void calcSquare(Number *num)
-{
- QMutexLocker locker(mutexpool.get(num));
- num.setNumber(num.number() * num.number());
-}
-//! [1]
diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qsemaphore.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qsemaphore.cpp
index a46e10c7b0..d7c9b900af 100644
--- a/src/corelib/doc/snippets/code/src_corelib_thread_qsemaphore.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_thread_qsemaphore.cpp
@@ -35,6 +35,12 @@ sem.tryAcquire(250, 1000); // sem.available() == 5, waits 1000 milliseconds a
sem.tryAcquire(3, 30000); // sem.available() == 2, returns true without waiting
//! [3]
+//! [tryAcquire-QDeadlineTimer]
+QSemaphore sem(5); // sem.available() == 5
+sem.tryAcquire(250, QDeadlineTimer(1000)); // sem.available() == 5, waits 1000 milliseconds and returns false
+sem.tryAcquire(3, QDeadlineTimer(30s)); // sem.available() == 2, returns true without waiting
+//! [tryAcquire-QDeadlineTimer]
+
//! [4]
// ... do something that may throw or return early
sem.release();
diff --git a/src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp b/src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp
index 4563e81f30..588e81bab1 100644
--- a/src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_time_qdatetime.cpp
@@ -71,14 +71,6 @@ QTime::isValid(22, 5, 62); // returns false
//! [9]
-//! [10]
-QTime t;
-t.start();
-some_lengthy_task();
-qDebug("Time elapsed: %d ms", t.elapsed());
-//! [10]
-
-
//! [11]
QDateTime now = QDateTime::currentDateTime();
QDateTime xmas(QDate(now.date().year(), 12, 25).startOfDay());
@@ -189,3 +181,11 @@ QDate firstMonday = 2020y / January / Monday[0];
// Last Monday of January 2020:
QDate lastMonday = 2020y / January / Monday[last];
//! [22]
+
+//! [23]
+QDateTime local(QDateTime::currentDateTime());
+QDateTime UTC(local.toTimeSpec(QTimeZone::UTC));
+qDebug() << "Local time is:" << local;
+qDebug() << "UTC time is:" << UTC;
+qDebug() << "No difference between times represented:" << local.secsTo(UTC);
+//! [23]
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser.cpp
index 6fc3cf5c3c..cc22ba88ce 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qcommandlineparser.cpp
@@ -90,12 +90,4 @@ Arguments:
//! [3]
}
-{
-//! [4]
-QCommandLineParser parser;
-parser.setApplicationDescription(QCoreApplication::translate("main", "The best application in the world"));
-parser.addHelpOption();
-//! [4]
-}
-
}
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
index b7e56c5ec3..c779b9e3e7 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qhash.cpp
@@ -42,7 +42,7 @@ QHash<int, QWidget *> hash;
...
for (int i = 0; i < 1000; ++i) {
if (hash[i] == okButton)
- cout << "Found button at index " << i << Qt::endl;
+ cout << "Found button at index " << i << endl;
}
//! [6]
@@ -51,17 +51,14 @@ for (int i = 0; i < 1000; ++i) {
QHashIterator<QString, int> i(hash);
while (i.hasNext()) {
i.next();
- cout << i.key() << ": " << i.value() << Qt::endl;
+ cout << qPrintable(i.key()) << ": " << i.value() << endl;
}
//! [7]
//! [8]
-QHash<QString, int>::const_iterator i = hash.constBegin();
-while (i != hash.constEnd()) {
- cout << i.key() << ": " << i.value() << Qt::endl;
- ++i;
-}
+for (auto i = hash.cbegin(), end = hash.cend(); i != end; ++i)
+ cout << qPrintable(i.key()) << ": " << i.value() << endl;
//! [8]
@@ -75,8 +72,8 @@ hash.insert("plenty", 2000);
//! [12]
QHash<QString, int> hash;
...
-foreach (int value, hash)
- cout << value << Qt::endl;
+for (int value : std::as_const(hash))
+ cout << value << endl;
//! [12]
@@ -138,7 +135,7 @@ QHash<QString, int> hash;
...
QHash<QString, int>::const_iterator i = hash.find("HDR");
while (i != hash.end() && i.key() == "HDR") {
- cout << i.value() << Qt::endl;
+ cout << i.value() << endl;
++i;
}
//! [16]
@@ -151,50 +148,20 @@ hash.insert("February", 2);
...
hash.insert("December", 12);
-QHash<QString, int>::iterator i;
-for (i = hash.begin(); i != hash.end(); ++i)
- cout << i.key() << ": " << i.value() << Qt::endl;
+for (auto i = hash.cbegin(), end = hash.cend(); i != end; ++i)
+ cout << qPrintable(key()) << ": " << i.value() << endl;
//! [17]
//! [18]
-QHash<QString, int>::iterator i;
-for (i = hash.begin(); i != hash.end(); ++i)
+for (auto i = hash.begin(), end = hash.end(); i != end; ++i)
i.value() += 2;
//! [18]
-
-//! [19]
-QHash<QString, int>::iterator i = hash.begin();
-while (i != hash.end()) {
- if (i.key().startsWith('_'))
- i = hash.erase(i);
- else
- ++i;
-}
-//! [19]
-
-
-//! [20]
-QHash<QString, int>::iterator i = hash.begin();
-while (i != hash.end()) {
- QHash<QString, int>::iterator prev = i;
- ++i;
- if (prev.key().startsWith('_'))
- hash.erase(prev);
-}
-//! [20]
-
-
//! [21]
-// WRONG
-while (i != hash.end()) {
- if (i.key().startsWith('_'))
- hash.erase(i);
- ++i;
-}
+erase_if(hash, [](const QHash<QString, int>::iterator it) { return it.value() > 10; });
//! [21]
-
+}
//! [22]
if (i.key() == "Hello")
@@ -209,9 +176,8 @@ hash.insert("February", 2);
...
hash.insert("December", 12);
-QHash<QString, int>::const_iterator i;
-for (i = hash.constBegin(); i != hash.constEnd(); ++i)
- cout << i.key() << ": " << i.value() << Qt::endl;
+for (auto i = hash.cbegin(), end = hash.cend(); i != end; ++i)
+ cout << qPrintable(i.key()) << ": " << i.value() << endl;
//! [23]
@@ -232,24 +198,24 @@ hash3 = hash1 + hash2;
//! [25]
QList<int> values = hash.values("plenty");
-for (int i = 0; i < values.size(); ++i)
- cout << values.at(i) << Qt::endl;
+for (auto i : std::as_const(values))
+ cout << i << endl;
//! [25]
//! [26]
-QMultiHash<QString, int>::iterator i = hash.find("plenty");
-while (i != hash.end() && i.key() == "plenty") {
- cout << i.value() << Qt::endl;
+auto i = hash.constFind("plenty");
+while (i != hash.cend() && i.key() == "plenty") {
+ cout << i.value() << endl;
++i;
}
//! [26]
//! [27]
-for (QHash<int, QString>::const_iterator it = hash.cbegin(), end = hash.cend(); it != end; ++it) {
- cout << "The key: " << it.key() << Qt::endl
- cout << "The value: " << it.value() << Qt::endl;
- cout << "Also the value: " << (*it) << Qt::endl;
+for (auto it = hash.cbegin(), end = hash.cend(); it != end; ++it) {
+ cout << "The key: " << it.key() << endl;
+ cout << "The value: " << qPrintable(it.value()) << endl;
+ cout << "Also the value: " << qPrintable(*it) << endl;
}
//! [27]
@@ -322,7 +288,7 @@ hash.insert("February", 2);
hash.insert("December", 12);
for (auto [key, value] : hash.asKeyValueRange()) {
- cout << key << ": " << value << Qt::endl;
+ cout << qPrintable(key) << ": " << value << endl;
--value; // convert to JS month indexing
}
//! [34]
@@ -335,7 +301,7 @@ hash.insert("February", 2);
hash.insert("December", 12);
for (auto [key, value] : hash.asKeyValueRange()) {
- cout << key << ": " << value << Qt::endl;
+ cout << qPrintable(key) << ": " << value << endl;
--value; // convert to JS month indexing
}
//! [35]
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qlist.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qlist.cpp
index 8957d43476..499e8fe480 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qlist.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qlist.cpp
@@ -26,7 +26,7 @@ if (list[0] == "Liz")
//! [4]
for (qsizetype i = 0; i < list.size(); ++i) {
if (list.at(i) == "Alfonso")
- cout << "Found Alfonso at position " << i << Qt::endl;
+ cout << "Found Alfonso at position " << i << endl;
}
//! [4]
@@ -34,7 +34,7 @@ for (qsizetype i = 0; i < list.size(); ++i) {
//! [5]
qsizetype i = list.indexOf("Harumi");
if (i != -1)
- cout << "First occurrence of Harumi is at position " << i << Qt::endl;
+ cout << "First occurrence of Harumi is at position " << i << endl;
//! [5]
@@ -101,16 +101,14 @@ list.prepend("three");
//! [9]
-QList<QString> list;
-list << "alpha" << "beta" << "delta";
+QList<QString> list = {"alpha", "beta", "delta"};
list.insert(2, "gamma");
// list: ["alpha", "beta", "gamma", "delta"]
//! [9]
//! [10]
-QList<double> list;
-list << 2.718 << 1.442 << 0.4342;
+QList<double> list = {2.718, 1.442, 0.4342};
list.insert(1, 3, 9.9);
// list: [2.718, 9.9, 9.9, 9.9, 1.442, 0.4342]
//! [10]
@@ -127,8 +125,7 @@ list.fill("oh", 5);
//! [12]
-QList<QString> list;
-list << "A" << "B" << "C" << "B" << "A";
+QList<QString> list{"A", "B", "C", "B", "A"};
list.indexOf("B"); // returns 1
list.indexOf("B", 1); // returns 1
list.indexOf("B", 2); // returns 3
@@ -137,8 +134,7 @@ list.indexOf("X"); // returns -1
//! [13]
-QList<QString> list;
-list << "A" << "B" << "C" << "B" << "A";
+QList<QString> list = {"A", "B", "C", "B", "A"};
list.lastIndexOf("B"); // returns 3
list.lastIndexOf("B", 3); // returns 3
list.lastIndexOf("B", 2); // returns 1
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp
index 552b7be80a..5f87211968 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qmap.cpp
@@ -42,7 +42,7 @@ QMap<int, QWidget *> map;
...
for (int i = 0; i < 1000; ++i) {
if (map[i] == okButton)
- cout << "Found button at index " << i << Qt::endl;
+ cout << "Found button at index " << i << endl;
}
//! [6]
@@ -51,17 +51,14 @@ for (int i = 0; i < 1000; ++i) {
QMapIterator<QString, int> i(map);
while (i.hasNext()) {
i.next();
- cout << i.key() << ": " << i.value() << Qt::endl;
+ cout << qPrintable(i.key()) << ": " << i.value() << endl;
}
//! [7]
//! [8]
-QMap<QString, int>::const_iterator i = map.constBegin();
-while (i != map.constEnd()) {
- cout << i.key() << ": " << i.value() << Qt::endl;
- ++i;
-}
+for (auto i = map.cbegin(), end = map.cend(); i != end; ++i)
+ cout << qPrintable(i.key()) << ": " << i.value() << endl;
//! [8]
@@ -75,8 +72,8 @@ map.insert("plenty", 2000);
//! [12]
QMap<QString, int> map;
...
-foreach (int value, map)
- cout << value << Qt::endl;
+for (int value : std::as_const(map))
+ cout << value << endl;
//! [12]
@@ -107,43 +104,6 @@ inline bool operator<(const Employee &e1, const Employee &e2)
//! [13]
-//! [14]
-QMap<QString, int> map;
-...
-QMap<QString, int>::const_iterator i = map.find("HDR");
-while (i != map.end() && i.key() == "HDR") {
- cout << i.value() << Qt::endl;
- ++i;
-}
-//! [14]
-
-
-//! [15]
-QMap<int, QString> map;
-map.insert(1, "one");
-map.insert(5, "five");
-map.insert(10, "ten");
-
-map.lowerBound(0); // returns iterator to (1, "one")
-map.lowerBound(1); // returns iterator to (1, "one")
-map.lowerBound(2); // returns iterator to (5, "five")
-map.lowerBound(10); // returns iterator to (10, "ten")
-map.lowerBound(999); // returns end()
-//! [15]
-
-
-//! [16]
-QMap<QString, int> map;
-...
-QMap<QString, int>::const_iterator i = map.lowerBound("HDR");
-QMap<QString, int>::const_iterator upperBound = map.upperBound("HDR");
-while (i != upperBound) {
- cout << i.value() << Qt::endl;
- ++i;
-}
-//! [16]
-
-
//! [17]
QMap<int, QString> map;
map.insert(1, "one");
@@ -165,50 +125,33 @@ map.insert("February", 2);
...
map.insert("December", 12);
-QMap<QString, int>::iterator i;
-for (i = map.begin(); i != map.end(); ++i)
- cout << i.key() << ": " << i.value() << Qt::endl;
+for (auto i = map.cbegin(), end = map.cend(); i != end; ++i)
+ cout << qPrintable(i.key()) << ": " << i.value() << endl;
//! [18]
//! [19]
-QMap<QString, int>::iterator i;
-for (i = map.begin(); i != map.end(); ++i)
+for (auto i = map.begin(), end = map.end(); i != end; ++i)
i.value() += 2;
//! [19]
+void erase()
+{
+QMap<QString, int> map;
//! [20]
-QMap<QString, int>::iterator i = map.begin();
-while (i != map.end()) {
- if (i.key().startsWith('_'))
+QMap<QString, int>::const_iterator i = map.cbegin();
+while (i != map.cend()) {
+ if (i.value() > 10)
i = map.erase(i);
else
++i;
}
//! [20]
-
-
//! [21]
-QMap<QString, int>::iterator i = map.begin();
-while (i != map.end()) {
- QMap<QString, int>::iterator prev = i;
- ++i;
- if (prev.key().startsWith('_'))
- map.erase(prev);
-}
+erase_if(map, [](const QMap<QString, int>::iterator it) { return it.value() > 10; });
//! [21]
-
-
-//! [22]
-// WRONG
-while (i != map.end()) {
- if (i.key().startsWith('_'))
- map.erase(i);
- ++i;
}
-//! [22]
-
//! [23]
if (i.key() == "Hello")
@@ -223,47 +166,16 @@ map.insert("February", 2);
...
map.insert("December", 12);
-QMap<QString, int>::const_iterator i;
-for (i = map.constBegin(); i != map.constEnd(); ++i)
- cout << i.key() << ": " << i.value() << Qt::endl;
+for (auto i = map.cbegin(), end = map.cend(); i != end; ++i)
+ cout << qPrintable(i.key()) << ": " << i.value() << endl;
//! [24]
-//! [25]
-QMultiMap<QString, int> map1, map2, map3;
-
-map1.insert("plenty", 100);
-map1.insert("plenty", 2000);
-// map1.size() == 2
-
-map2.insert("plenty", 5000);
-// map2.size() == 1
-
-map3 = map1 + map2;
-// map3.size() == 3
-//! [25]
-
-
-//! [26]
-QList<int> values = map.values("plenty");
-for (int i = 0; i < values.size(); ++i)
- cout << values.at(i) << Qt::endl;
-//! [26]
-
-
-//! [27]
-QMultiMap<QString, int>::iterator i = map.find("plenty");
-while (i != map.end() && i.key() == "plenty") {
- cout << i.value() << Qt::endl;
- ++i;
-}
-//! [27]
-
//! [keyiterator1]
for (QMap<int, QString>::const_iterator it = map.cbegin(), end = map.cend(); it != end; ++it) {
- cout << "The key: " << it.key() << Qt::endl
- cout << "The value: " << it.value() << Qt::endl;
- cout << "Also the value: " << (*it) << Qt::endl;
+ cout << "The key: " << it.key() << endl;
+ cout << "The value: " << qPrintable(it.value()) << endl;
+ cout << "Also the value: " << qPrintable(*it) << endl;
}
//! [keyiterator1]
@@ -286,7 +198,7 @@ map.insert("February", 2);
map.insert("December", 12);
for (auto [key, value] : map.asKeyValueRange()) {
- cout << key << ": " << value << Qt::endl;
+ cout << qPrintable(key) << ": " << value << endl;
--value; // convert to JS month indexing
}
//! [28]
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qmultimap.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qmultimap.cpp
index 60793ab111..42ec46585b 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qmultimap.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qmultimap.cpp
@@ -19,8 +19,8 @@ multimap.insert("c", -5);
int num2 = multimap.value("a"); // 1
int num3 = multimap.value("thirteen"); // not found; 0
int num3 = 0;
-auto it = multimap.value("b");
-if (it != multimap.end()) {
+auto it = multimap.constFind("b");
+if (it != multimap.cend()) {
num3 = it.value();
}
//! [3]
@@ -47,17 +47,14 @@ int timeout = multimap.value("TIMEOUT", 30);
QMultiMapIterator<QString, int> i(multimap);
while (i.hasNext()) {
i.next();
- cout << i.key() << ": " << i.value() << Qt::endl;
+ cout << qPrintable(i.key()) << ": " << i.value() << endl;
}
//! [7]
//! [8]
-auto i = multimap.constBegin();
-while (i != multimap.constEnd()) {
- cout << i.key() << ": " << i.value() << Qt::endl;
- ++i;
-}
+for (auto i = multimap.cbegin(), end = multimap.cend(); i != end; ++i)
+ cout << qPrintable(i.key()) << ": " << i.value() << endl;
//! [8]
@@ -70,22 +67,22 @@ multimap.insert("plenty", 2000);
//! [10]
QList<int> values = multimap.values("plenty");
-for (int i = 0; i < values.size(); ++i)
- cout << values.at(i) << Qt::endl;
+for (auto i : std::as_const(values))
+ cout << i << endl;
//! [10]
//! [11]
-QMultiMap<QString, int>::iterator i = multimap.find("plenty");
+auto i = multimap.find("plenty");
while (i != map.end() && i.key() == "plenty") {
- cout << i.value() << Qt::endl;
+ cout << i.value() << endl;
++i;
}
// better:
auto [i, end] = multimap.equal_range("plenty");
while (i != end) {
- cout << i.value() << Qt::endl;
+ cout << i.value() << endl;
++i;
}
//! [11]
@@ -94,8 +91,8 @@ while (i != end) {
//! [12]
QMap<QString, int> multimap;
...
-foreach (int value, multimap)
- cout << value << Qt::endl;
+for (int value : std::as_const(multimap))
+ cout << value << endl;
//! [12]
@@ -149,7 +146,7 @@ QMap<QString, int> multimap;
QMap<QString, int>::const_iterator i = multimap.lowerBound("HDR");
QMap<QString, int>::const_iterator upperBound = multimap.upperBound("HDR");
while (i != upperBound) {
- cout << i.value() << Qt::endl;
+ cout << i.value() << endl;
++i;
}
//! [16]
@@ -171,57 +168,27 @@ multimap.upperBound(10); // returns end()
multimap.upperBound(999); // returns end()
//! [17]
-
-//! [18]
-QMultiMap<QString, int> multimap;
-multimap.insert("January", 1);
-multimap.insert("February", 2);
-...
-multimap.insert("December", 12);
-
-QMap<QString, int>::iterator i;
-for (i = multimap.begin(); i != multimap.end(); ++i)
- cout << i.key() << ": " << i.value() << Qt::endl;
-//! [18]
-
-
//! [19]
-QMultiMap<QString, int>::iterator i;
-for (i = multimap.begin(); i != multimap.end(); ++i)
+for (auto it = multimap.begin(), end = multimap.end(); i != end; ++i)
i.value() += 2;
//! [19]
-
+void erase()
+{
+QMultiMap<QString, int> multimap;
//! [20]
-QMultiMap<QString, int>::iterator i = multimap.begin();
-while (i != multimap.end()) {
- if (i.key().startsWith('_'))
+QMultiMap<QString, int>::const_iterator i = multimap.cbegin();
+while (i != multimap.cend()) {
+ if (i.value() > 10)
i = multimap.erase(i);
else
++i;
}
//! [20]
-
-
//! [21]
-QMultiMap<QString, int>::iterator i = multimap.begin();
-while (i != multimap.end()) {
- QMap<QString, int>::iterator prev = i;
- ++i;
- if (prev.key().startsWith('_'))
- multimap.erase(prev);
-}
+erase_if(multimap, [](const QMultiMap<QString, int>::iterator it) { return it.value() > 10; });
//! [21]
-
-
-//! [22]
-// WRONG
-while (i != multimap.end()) {
- if (i.key().startsWith('_'))
- multimap.erase(i);
- ++i;
}
-//! [22]
//! [23]
@@ -237,9 +204,8 @@ multimap.insert("February", 2);
...
multimap.insert("December", 12);
-QMultiMap<QString, int>::const_iterator i;
-for (i = multimap.constBegin(); i != multimap.constEnd(); ++i)
- cout << i.key() << ": " << i.value() << Qt::endl;
+for (auto i = multimap.cbegin(), end = multimap.cend(); i != end; ++i)
+ cout << qPrintable(i.key()) << ": " << i.value() << endl;
//! [24]
@@ -258,10 +224,10 @@ map3 = map1 + map2;
//! [25]
//! [keyiterator1]
-for (QMultiMap<int, QString>::const_iterator it = multimap.cbegin(), end = multimap.cend(); it != end; ++it) {
- cout << "The key: " << it.key() << Qt::endl
- cout << "The value: " << it.value() << Qt::endl;
- cout << "Also the value: " << (*it) << Qt::endl;
+for (auto it = multimap.cbegin(), end = multimap.cend(); it != end; ++it) {
+ cout << "The key: " << it.key() << endl
+ cout << "The value: " << qPrintable(it.value()) << endl;
+ cout << "Also the value: " << qPrintable(*it) << endl;
}
//! [keyiterator1]
@@ -284,7 +250,7 @@ map.insert("February", 2);
map.insert("December", 12);
for (auto [key, value] : map.asKeyValueRange()) {
- cout << key << ": " << value << Qt::endl;
+ cout << qPrintable(key) << ": " << value << endl;
--value; // convert to JS month indexing
}
//! [26]
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qqueue.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qqueue.cpp
index 81b8eb4dbd..c59ec1060a 100644
--- a/src/corelib/doc/snippets/code/src_corelib_tools_qqueue.cpp
+++ b/src/corelib/doc/snippets/code/src_corelib_tools_qqueue.cpp
@@ -7,5 +7,5 @@ queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(3);
while (!queue.isEmpty())
- cout << queue.dequeue() << Qt::endl;
+ cout << queue.dequeue() << endl;
//! [0]
diff --git a/src/corelib/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp b/src/corelib/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp
deleted file mode 100644
index 0b307c33c4..0000000000
--- a/src/corelib/doc/snippets/code/src_gui_dialogs_qmessagebox.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-//! [0]
-int ret = QMessageBox::warning(this, tr("My Application"),
- tr("The document has been modified.\n"
- "Do you want to save your changes?"),
- QMessageBox::Save | QMessageBox::Discard
- | QMessageBox::Cancel,
- QMessageBox::Save);
-//! [0]
-
-
-//! [1]
-QMessageBox msgBox;
-msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
-switch (msgBox.exec()) {
-case QMessageBox::Yes:
- // yes was clicked
- break;
-case QMessageBox::No:
- // no was clicked
- break;
-default:
- // should never be reached
- break;
-}
-//! [1]
-
-
-//! [2]
-QMessageBox msgBox;
-QPushButton *connectButton = msgBox.addButton(tr("Connect"), QMessageBox::ActionRole);
-QPushButton *abortButton = msgBox.addButton(QMessageBox::Abort);
-
-msgBox.exec();
-
-if (msgBox.clickedButton() == connectButton) {
- // connect
-} else if (msgBox.clickedButton() == abortButton) {
- // abort
-}
-//! [2]
-
-
-//! [3]
-QMessageBox messageBox(this);
-QAbstractButton *disconnectButton =
- messageBox.addButton(tr("Disconnect"), QMessageBox::ActionRole);
-...
-messageBox.exec();
-if (messageBox.clickedButton() == disconnectButton) {
- ...
-}
-//! [3]
-
-
-//! [4]
-#include <QApplication>
-#include <QMessageBox>
-
-int main(int argc, char *argv[])
-{
- QT_REQUIRE_VERSION(argc, argv, "6.1.2")
-
- QApplication app(argc, argv);
- ...
- return app.exec();
-}
-//! [4]
-
-//! [5]
-QMessageBox msgBox;
-msgBox.setText("The document has been modified.");
-msgBox.exec();
-//! [5]
-
-//! [6]
-QMessageBox msgBox;
-msgBox.setText("Do you want to save your changes?");
-msgBox.setInformativeText("The document has been modified. It was last saved 5 days ago.");
-msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
-msgBox.setDefaultButton(QMessageBox::Save);
-int ret = msgBox.exec();
-//! [6]
-
-//! [7]
-switch (ret) {
- case QMessageBox::Save:
- // Save was clicked
- break;
- case QMessageBox::Discard:
- // Don't Save was clicked
- break;
- case QMessageBox::Cancel:
- // Cancel was clicked
- break;
- default:
- // should never be reached
- break;
-}
-//! [7]
-
-//! [9]
-QMessageBox msgBox(this);
-msgBox.setText(tr("The document has been modified.\n"
- "Do you want to save your changes?"));
-msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard
- | QMessageBox::Cancel);
-msgBox.setDefaultButton(QMessageBox::Save);
-//! [9]
diff --git a/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp b/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp
index 52934b6159..4ef1891cdb 100644
--- a/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp
+++ b/src/corelib/doc/snippets/code/src_gui_itemviews_qidentityproxymodel.cpp
@@ -17,10 +17,16 @@ class DateFormatProxyModel : public QIdentityProxyModel
return QIdentityProxyModel::data(index, role);
const QDateTime dateTime = sourceModel()->data(SourceClass::DateRole).toDateTime();
-
return dateTime.toString(m_formatString);
}
+ QMap<int, QVariant> itemData(const QModelIndex &proxyIndex) const override
+ {
+ QMap<int, QVariant> map = QIdentityProxyModel::itemData(proxyIndex);
+ map[Qt::DisplayRole] = data(proxyIndex);
+ return map;
+ }
+
private:
QString m_formatString;
};
diff --git a/src/corelib/doc/snippets/customtype/customtypeexample.cpp b/src/corelib/doc/snippets/customtype/customtypeexample.cpp
new file mode 100644
index 0000000000..afa2c4b268
--- /dev/null
+++ b/src/corelib/doc/snippets/customtype/customtypeexample.cpp
@@ -0,0 +1,90 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QCoreApplication>
+#include <QDebug>
+#include <QVariant>
+
+//message.h
+
+//! [custom type definition]
+class Message
+{
+public:
+ Message() = default;
+ ~Message() = default;
+ Message(const Message &) = default;
+ Message &operator=(const Message &) = default;
+
+ Message(const QString &body, const QStringList &headers);
+
+ QStringView body() const;
+ QStringList headers() const;
+
+private:
+ QString m_body;
+ QStringList m_headers;
+};
+//! [custom type definition]
+
+//! [custom type meta-type declaration]
+Q_DECLARE_METATYPE(Message);
+//! [custom type meta-type declaration]
+
+//! [custom type streaming operator declaration]
+QDebug operator<<(QDebug dbg, const Message &message);
+//! [custom type streaming operator declaration]
+
+// message.cpp
+
+//! [custom type streaming operator]
+QDebug operator<<(QDebug dbg, const Message &message)
+{
+ const QList<QStringView> pieces = message.body().split(u"\r\n", Qt::SkipEmptyParts);
+ if (pieces.isEmpty())
+ dbg.nospace() << "Message()";
+ else if (pieces.size() == 1)
+ dbg.nospace() << "Message(" << pieces.first() << ")";
+ else
+ dbg.nospace() << "Message(" << pieces.first() << " ...)";
+ return dbg;
+}
+//! [custom type streaming operator]
+
+//! [getter functions]
+QStringView Message::body() const
+{
+ return m_body;
+}
+
+QStringList Message::headers() const
+{
+ return m_headers;
+}
+//! [getter functions]
+
+//main.cpp
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication app(argc, argv);
+ QStringList headers;
+ headers << "Subject: Hello World"
+ << "From: address@example.com";
+ QString body = "This is a test.\r\n";
+ //! [printing a custom type]
+ Message message(body, headers);
+ qDebug() << "Original:" << message;
+ //! [printing a custom type]
+ //! [storing a custom value]
+ QVariant stored;
+ stored.setValue(message);
+ //! [storing a custom value]
+ qDebug() << "Stored:" << stored;
+ //! [retrieving a custom value]
+ Message retrieved = qvariant_cast<Message>(stored);
+ qDebug() << "Retrieved:" << retrieved;
+ retrieved = qvariant_cast<Message>(stored);
+ qDebug() << "Retrieved:" << retrieved;
+ //! [retrieving a custom value]
+ return 0;
+}
diff --git a/src/corelib/doc/snippets/jni/src_qjniobject.cpp b/src/corelib/doc/snippets/jni/src_qjniobject.cpp
index ca402fa3d7..6e66b51383 100644
--- a/src/corelib/doc/snippets/jni/src_qjniobject.cpp
+++ b/src/corelib/doc/snippets/jni/src_qjniobject.cpp
@@ -1,23 +1,6 @@
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [Working with lists]
-QStringList getTrackTitles(const QJniObject &album) {
- QStringList stringList;
- QJniObject list = album.callObjectMethod("getTitles",
- "()Ljava/util/List;");
-
- if (list.isValid()) {
- const int size = list.callMethod<jint>("size");
- for (int i = 0; i < size; ++i) {
- QJniObject title = list.callObjectMethod("get", "(I)Ljava/lang/Object;", i);
- stringList.append(title.toString());
- }
- }
- return stringList;
-}
-//! [Working with lists]
-
//! [QJniObject scope]
void functionScope()
{
diff --git a/src/corelib/doc/snippets/ntfsp.cpp b/src/corelib/doc/snippets/ntfsp.cpp
index b4d59e6ac5..18f9bd0c5e 100644
--- a/src/corelib/doc/snippets/ntfsp.cpp
+++ b/src/corelib/doc/snippets/ntfsp.cpp
@@ -11,3 +11,18 @@ qt_ntfs_permission_lookup++; // turn checking on
qt_ntfs_permission_lookup--; // turn it off again
//! [1]
+//! [raii]
+void complexFunction()
+{
+ QNtfsPermissionCheckGuard permissionGuard; // check is enabled
+
+ // do complex things here that need permission check enabled
+
+} // as the guard goes out of scope the check is disabled
+//! [raii]
+
+//! [free-funcs]
+qAreNtfsPermissionChecksEnabled(); // check status
+qEnableNtfsPermissionChecks(); // turn checking on
+qDisableNtfsPermissionChecks(); // turn it off again
+//! [free-funcs]
diff --git a/src/corelib/doc/snippets/qloggingcategory/main.cpp b/src/corelib/doc/snippets/qloggingcategory/main.cpp
index 33aba3bf35..8b3a61d51f 100644
--- a/src/corelib/doc/snippets/qloggingcategory/main.cpp
+++ b/src/corelib/doc/snippets/qloggingcategory/main.cpp
@@ -131,6 +131,20 @@ oldCategoryFilter = QLoggingCategory::installFilter(myCategoryFilter);
//![15]
}
+ {
+//![16]
+ QLoggingCategory category("driver.usb");
+ qCFatal(category) << "a fatal message. Program will be terminated!";
+//![16]
+ }
+
+ {
+//![17]
+ QLoggingCategory category("driver.usb");
+ qCFatal(category, "a fatal message. Program will be terminated!");
+//![17]
+ }
+
return 0;
}
diff --git a/src/corelib/doc/snippets/qmessageauthenticationcode/main.cpp b/src/corelib/doc/snippets/qmessageauthenticationcode/main.cpp
index 90ea384319..21c55568ca 100644
--- a/src/corelib/doc/snippets/qmessageauthenticationcode/main.cpp
+++ b/src/corelib/doc/snippets/qmessageauthenticationcode/main.cpp
@@ -1,3 +1,4 @@
+// Copyright (C) 2023 The Qt Company Ltd.
// Copyright (C) 2016 Ruslan Nigmatullin <euroelessar@yandex.ru>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
@@ -13,13 +14,12 @@ int main(int argc, char *argv[])
//! [0]
//! [1]
- QMessageAuthenticationCode code(QCryptographicHash::Sha1);
- code.setKey(key);
+ QMessageAuthenticationCode code(QCryptographicHash::Sha256, key);
code.addData(message);
- code.result().toHex(); // returns "de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9"
+ code.result().toHex(); // returns "f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8"
//! [1]
//! [2]
- QMessageAuthenticationCode::hash(message, key, QCryptographicHash::Sha1).toHex();
+ QMessageAuthenticationCode::hash(message, key, QCryptographicHash::Sha256).toHex();
//! [2]
}
diff --git a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp
index 235d8b27db..e2e97fa11c 100644
--- a/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp
+++ b/src/corelib/doc/snippets/qsignalmapper/buttonwidget.cpp
@@ -14,7 +14,7 @@ ButtonWidget::ButtonWidget(const QStringList &texts, QWidget *parent)
QGridLayout *gridLayout = new QGridLayout(this);
for (int i = 0; i < texts.size(); ++i) {
QPushButton *button = new QPushButton(texts[i]);
- connect(button, &QPushButton::clicked, signalMapper, &QSignalMapper::map);
+ connect(button, &QPushButton::clicked, signalMapper, qOverload<>(&QSignalMapper::map));
//! [0] //! [1]
signalMapper->setMapping(button, texts[i]);
gridLayout->addWidget(button, i / 3, i % 3);
diff --git a/src/corelib/doc/snippets/qstring/main.cpp b/src/corelib/doc/snippets/qstring/main.cpp
index c6f35339c6..8b39ae2f13 100644
--- a/src/corelib/doc/snippets/qstring/main.cpp
+++ b/src/corelib/doc/snippets/qstring/main.cpp
@@ -41,6 +41,7 @@ public:
void firstFunction();
void leftJustifiedFunction();
void slicedFunction();
+ void sliceFunction();
void numberFunction();
void prependFunction();
@@ -909,6 +910,15 @@ void Widget::arrayOperator()
//! [85]
}
+void Widget::sliceFunction()
+{
+ //! [86]
+ QString x = u"Nine pineapples"_s;
+ x.slice(5); // x == "pineapples"
+ x.slice(4, 3); // x == "app"
+ //! [86]
+}
+
int main(int argc, char *argv[])
{
diff --git a/src/corelib/doc/snippets/qstring/stringbuilder.cpp b/src/corelib/doc/snippets/qstring/stringbuilder.cpp
index 6b3175d48a..c3a709bd4c 100644
--- a/src/corelib/doc/snippets/qstring/stringbuilder.cpp
+++ b/src/corelib/doc/snippets/qstring/stringbuilder.cpp
@@ -1,6 +1,8 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QString>
+
using namespace Qt::StringLiterals;
//! [0]
@@ -13,10 +15,6 @@ using namespace Qt::StringLiterals;
...
//! [0]
-//! [3]
- DEFINES *= QT_USE_QSTRINGBUILDER
-//! [3]
-
//! [5]
#include <QStringBuilder>
@@ -25,3 +23,24 @@ using namespace Qt::StringLiterals;
QLatin1StringView world("world");
QString message = hello % el % world % QChar('!');
//! [5]
+
+//! [6]
+ QString str("QStringBuilder");
+
+ // "s" type is deduced as QStringBuilder<...>
+ auto s = "Like hot glue, " % str % " concatenates strings";
+
+ // Similarly the return type of this lambda is deduced as QStringBuilder<...>
+ auto concatenateStr = []() {
+ return "Like hot glue, " % str % " concatenates strings";
+ };
+//! [6]
+
+//! [7]
+ QString s = "Like hot glue, " % str % " concatenates strings";
+
+ // With a lambda, specify a trailing return type:
+ auto concatenateStr = []() -> QString {
+ return "Like hot glue, " % str % " concatenates strings";
+ };
+//! [7]
diff --git a/src/corelib/doc/snippets/qstringlist/main.cpp b/src/corelib/doc/snippets/qstringlist/main.cpp
index d2175aafb5..1b7453cf6a 100644
--- a/src/corelib/doc/snippets/qstringlist/main.cpp
+++ b/src/corelib/doc/snippets/qstringlist/main.cpp
@@ -66,7 +66,7 @@ Widget::Widget(QWidget *parent)
result.clear();
//! [12]
- foreach (const QString &str, list) {
+ for (const auto &str : std::as_const(list)) {
if (str.contains("Bill"))
result += str;
}
@@ -93,6 +93,13 @@ Widget::Widget(QWidget *parent)
// list == ["Bill Clinton", "Bill Murray"]
//! [17]
+ {
+//! [18]
+ QStringList veryLongList;
+ QStringMatcher matcher(u"Straße", Qt::CaseInsensitive);
+ QStringList filtered = veryLongList.filter(matcher);
+//! [18]
+ }
}
int main(int argc, char *argv[])
diff --git a/src/corelib/doc/snippets/resource-system/CMakeLists.txt b/src/corelib/doc/snippets/resource-system/CMakeLists.txt
index 267e9a59ad..f0ec0f6816 100644
--- a/src/corelib/doc/snippets/resource-system/CMakeLists.txt
+++ b/src/corelib/doc/snippets/resource-system/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
project(my_app)
cmake_minimum_required(VERSION 3.16)
diff --git a/src/corelib/doc/snippets/resource-system/application.pro b/src/corelib/doc/snippets/resource-system/application.pro
index 4b1f1d7635..42c66eba4c 100644
--- a/src/corelib/doc/snippets/resource-system/application.pro
+++ b/src/corelib/doc/snippets/resource-system/application.pro
@@ -2,9 +2,9 @@ TEMPLATE = app
QT += qml widgets
-#! [0]
+#! [0] #! [qrc]
RESOURCES = application.qrc
-#! [0]
+#! [0] #! [qrc]
#! [1]
resources.files = \
diff --git a/src/corelib/doc/snippets/resource-system/mainwindow.cpp b/src/corelib/doc/snippets/resource-system/mainwindow.cpp
index 92456c35c4..de98aa56ec 100644
--- a/src/corelib/doc/snippets/resource-system/mainwindow.cpp
+++ b/src/corelib/doc/snippets/resource-system/mainwindow.cpp
@@ -1,15 +1,10 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [0]
#include <QtWidgets>
#include "mainwindow.h"
-//! [0]
-
-//! [1]
MainWindow::MainWindow()
-//! [1] //! [2]
{
textEdit = new QPlainTextEdit;
setCentralWidget(textEdit);
@@ -27,11 +22,8 @@ MainWindow::MainWindow()
setCurrentFile(QString());
setUnifiedTitleAndToolBarOnMac(true);
}
-//! [2]
-//! [3]
void MainWindow::closeEvent(QCloseEvent *event)
-//! [3] //! [4]
{
if (maybeSave()) {
writeSettings();
@@ -40,22 +32,16 @@ void MainWindow::closeEvent(QCloseEvent *event)
event->ignore();
}
}
-//! [4]
-//! [5]
void MainWindow::newFile()
-//! [5] //! [6]
{
if (maybeSave()) {
textEdit->clear();
setCurrentFile(QString());
}
}
-//! [6]
-//! [7]
void MainWindow::open()
-//! [7] //! [8]
{
if (maybeSave()) {
QString fileName = QFileDialog::getOpenFileName(this);
@@ -63,11 +49,8 @@ void MainWindow::open()
loadFile(fileName);
}
}
-//! [8]
-//! [9]
bool MainWindow::save()
-//! [9] //! [10]
{
if (curFile.isEmpty()) {
return saveAs();
@@ -75,11 +58,8 @@ bool MainWindow::save()
return saveFile(curFile);
}
}
-//! [10]
-//! [11]
bool MainWindow::saveAs()
-//! [11] //! [12]
{
QString fileName = QFileDialog::getSaveFileName(this);
if (fileName.isEmpty())
@@ -87,42 +67,31 @@ bool MainWindow::saveAs()
return saveFile(fileName);
}
-//! [12]
-//! [13]
void MainWindow::about()
-//! [13] //! [14]
{
QMessageBox::about(this, tr("About Application"),
tr("The <b>Application</b> example demonstrates how to "
"write modern GUI applications using Qt, with a menu bar, "
"toolbars, and a status bar."));
}
-//! [14]
-//! [15]
void MainWindow::documentWasModified()
-//! [15] //! [16]
{
setWindowModified(textEdit->document()->isModified());
}
-//! [16]
-//! [17]
void MainWindow::createActions()
-//! [17] //! [18]
{
newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
newAct->setShortcuts(QKeySequence::New);
newAct->setStatusTip(tr("Create a new file"));
connect(newAct, &QAction::triggered, this, &MainWindow::newFile);
-//! [19]
openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
openAct->setShortcuts(QKeySequence::Open);
openAct->setStatusTip(tr("Open an existing file"));
connect(openAct, &QAction::triggered, this, &MainWindow::open);
-//! [18] //! [19]
saveAct = new QAction(QIcon(":/images/save.png"), tr("&Save"), this);
saveAct->setShortcuts(QKeySequence::Save);
@@ -134,10 +103,8 @@ void MainWindow::createActions()
saveAsAct->setStatusTip(tr("Save the document under a new name"));
connect(saveAsAct, &QAction::triggered, this, &MainWindow::saveAs);
-//! [20]
exitAct = new QAction(tr("E&xit"), this);
exitAct->setShortcuts(QKeySequence::Quit);
-//! [20]
exitAct->setStatusTip(tr("Exit the application"));
connect(exitAct, &QAction::triggered, this, &MainWindow::close);
@@ -165,34 +132,24 @@ void MainWindow::createActions()
aboutAct->setStatusTip(tr("Show the application's About box"));
connect(aboutAct, &QAction::triggered, this, &MainWindow::about);
-//! [22]
aboutQtAct = new QAction(tr("About &Qt"), this);
aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
connect(aboutQtAct, &QAction::triggered, qApp, &QApplication::aboutQt);
-//! [22]
-//! [23]
cutAct->setEnabled(false);
-//! [23] //! [24]
copyAct->setEnabled(false);
connect(textEdit, &QTextEdit::copyAvailable,
cutAct, &QAction::setEnabled);
connect(textEdit, &QTextEdit::copyAvailable,
copyAct, &QAction::setEnabled);
}
-//! [24]
-//! [25] //! [26]
void MainWindow::createMenus()
-//! [25] //! [27]
{
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(newAct);
-//! [28]
fileMenu->addAction(openAct);
-//! [28]
fileMenu->addAction(saveAct);
-//! [26]
fileMenu->addAction(saveAsAct);
fileMenu->addSeparator();
fileMenu->addAction(exitAct);
@@ -208,16 +165,12 @@ void MainWindow::createMenus()
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
}
-//! [27]
-//! [29] //! [30]
void MainWindow::createToolBars()
{
fileToolBar = addToolBar(tr("File"));
fileToolBar->addAction(newAct);
-//! [29] //! [31]
fileToolBar->addAction(openAct);
-//! [31]
fileToolBar->addAction(saveAct);
editToolBar = addToolBar(tr("Edit"));
@@ -225,19 +178,13 @@ void MainWindow::createToolBars()
editToolBar->addAction(copyAct);
editToolBar->addAction(pasteAct);
}
-//! [30]
-//! [32]
void MainWindow::createStatusBar()
-//! [32] //! [33]
{
statusBar()->showMessage(tr("Ready"));
}
-//! [33]
-//! [34] //! [35]
void MainWindow::readSettings()
-//! [34] //! [36]
{
QSettings settings("QtProject", "Application Example");
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
@@ -245,21 +192,15 @@ void MainWindow::readSettings()
resize(size);
move(pos);
}
-//! [35] //! [36]
-//! [37] //! [38]
void MainWindow::writeSettings()
-//! [37] //! [39]
{
QSettings settings("QtProject", "Application Example");
settings.setValue("pos", pos());
settings.setValue("size", size());
}
-//! [38] //! [39]
-//! [40]
bool MainWindow::maybeSave()
-//! [40] //! [41]
{
if (textEdit->document()->isModified()) {
QMessageBox::StandardButton ret;
@@ -274,11 +215,8 @@ bool MainWindow::maybeSave()
}
return true;
}
-//! [41]
-//! [42]
void MainWindow::loadFile(const QString &fileName)
-//! [42] //! [43]
{
QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
@@ -301,11 +239,8 @@ void MainWindow::loadFile(const QString &fileName)
setCurrentFile(fileName);
statusBar()->showMessage(tr("File loaded"), 2000);
}
-//! [43]
-//! [44]
bool MainWindow::saveFile(const QString &fileName)
-//! [44] //! [45]
{
QFile file(fileName);
if (!file.open(QFile::WriteOnly | QFile::Text)) {
@@ -329,11 +264,8 @@ bool MainWindow::saveFile(const QString &fileName)
statusBar()->showMessage(tr("File saved"), 2000);
return true;
}
-//! [45]
-//! [46]
void MainWindow::setCurrentFile(const QString &fileName)
-//! [46] //! [47]
{
curFile = fileName;
textEdit->document()->setModified(false);
@@ -344,12 +276,8 @@ void MainWindow::setCurrentFile(const QString &fileName)
shownName = "untitled.txt";
setWindowFilePath(shownName);
}
-//! [47]
-//! [48]
QString MainWindow::strippedName(const QString &fullFileName)
-//! [48] //! [49]
{
return QFileInfo(fullFileName).fileName();
}
-//! [49]
diff --git a/src/corelib/doc/snippets/signalsandslots/signalsandslots.h b/src/corelib/doc/snippets/signalsandslots/signalsandslots.h
index 2f5a53231c..a590e8fd5e 100644
--- a/src/corelib/doc/snippets/signalsandslots/signalsandslots.h
+++ b/src/corelib/doc/snippets/signalsandslots/signalsandslots.h
@@ -33,6 +33,8 @@ class Counter : public QObject
{
Q_OBJECT
+// Note. The Q_OBJECT macro starts a private section.
+// To declare public members, use the 'public:' access modifier.
public:
Counter() { m_value = 0; }
diff --git a/src/corelib/doc/snippets/threads/threads.cpp b/src/corelib/doc/snippets/threads/threads.cpp
index 57c68cd358..502bc4bfe0 100644
--- a/src/corelib/doc/snippets/threads/threads.cpp
+++ b/src/corelib/doc/snippets/threads/threads.cpp
@@ -7,9 +7,7 @@
#define Counter ReentrantCounter
-//! [3]
class Counter
-//! [3] //! [4]
{
public:
Counter() { n = 0; }
@@ -21,14 +19,11 @@ public:
private:
int n;
};
-//! [4]
#undef Counter
#define Counter ThreadSafeCounter
-//! [5]
class Counter
-//! [5] //! [6]
{
public:
Counter() { n = 0; }
@@ -41,7 +36,6 @@ private:
mutable QMutex mutex;
int n;
};
-//! [6]
typedef int SomeClass;
diff --git a/src/corelib/doc/snippets/timers/analogclock.cpp b/src/corelib/doc/snippets/timers/analogclock.cpp
index 4052c185c4..5241e57879 100644
--- a/src/corelib/doc/snippets/timers/analogclock.cpp
+++ b/src/corelib/doc/snippets/timers/analogclock.cpp
@@ -5,7 +5,8 @@
#include "analogclock.h"
-//! [0] //! [1]
+// QTimer
+//! [0]
AnalogClock::AnalogClock(QWidget *parent)
//! [0] //! [2]
: QWidget(parent)
@@ -23,11 +24,24 @@ AnalogClock::AnalogClock(QWidget *parent)
resize(200, 200);
//! [7]
}
-//! [1] //! [7]
+//! [7]
+
+//! [analogclock-qchronotimer]
+AnalogClock::AnalogClock(QWidget *parent)
+
+ : QWidget(parent)
+{
+ auto *timer = new QChronoTimer(1s, this);
+ connect(timer, &QTimer::timeout, this, QOverload<>::of(&AnalogClock::update));
+ timer->start();
+ ...
+ ...
+ setWindowTitle(tr("Analog Clock"));
+ resize(200, 200);
+}
+//! [analogclock-qchronotimer]
-//! [8] //! [9]
void AnalogClock::paintEvent(QPaintEvent *)
-//! [8] //! [10]
{
static const QPoint hourHand[3] = {
QPoint(7, 8),
@@ -45,64 +59,40 @@ void AnalogClock::paintEvent(QPaintEvent *)
int side = qMin(width(), height());
QTime time = QTime::currentTime();
-//! [10]
-//! [11]
QPainter painter(this);
-//! [11] //! [12]
painter.setRenderHint(QPainter::Antialiasing);
-//! [12] //! [13]
painter.translate(width() / 2, height() / 2);
-//! [13] //! [14]
painter.scale(side / 200.0, side / 200.0);
-//! [9] //! [14]
-//! [15]
painter.setPen(Qt::NoPen);
-//! [15] //! [16]
painter.setBrush(hourColor);
-//! [16]
-//! [17] //! [18]
painter.save();
-//! [17] //! [19]
painter.rotate(30.0 * ((time.hour() + time.minute() / 60.0)));
painter.drawConvexPolygon(hourHand, 3);
painter.restore();
-//! [18] //! [19]
-//! [20]
painter.setPen(hourColor);
-//! [20] //! [21]
for (int i = 0; i < 12; ++i) {
painter.drawLine(88, 0, 96, 0);
painter.rotate(30.0);
}
-//! [21]
-//! [22]
painter.setPen(Qt::NoPen);
-//! [22] //! [23]
painter.setBrush(minuteColor);
-//! [24]
painter.save();
painter.rotate(6.0 * (time.minute() + time.second() / 60.0));
painter.drawConvexPolygon(minuteHand, 3);
painter.restore();
-//! [23] //! [24]
-//! [25]
painter.setPen(minuteColor);
-//! [25] //! [26]
-//! [27]
for (int j = 0; j < 60; ++j) {
if ((j % 5) != 0)
painter.drawLine(92, 0, 96, 0);
painter.rotate(6.0);
}
-//! [27]
}
-//! [26]
diff --git a/src/corelib/doc/snippets/timers/timers.cpp b/src/corelib/doc/snippets/timers/timers.cpp
index c89db6890c..1a97ba535e 100644
--- a/src/corelib/doc/snippets/timers/timers.cpp
+++ b/src/corelib/doc/snippets/timers/timers.cpp
@@ -1,8 +1,12 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+#include <QChronoTimer>
+#include <QObject>
#include <QTimer>
+using namespace std::chrono;
+
class Foo : public QObject
{
public:
@@ -35,7 +39,45 @@ Foo::Foo()
}
}
-int main()
+// QChronoTimer
+class MyWidget : QObject
{
+ MyWidget()
+ {
+//! [qchronotimer-singleshot]
+ MyWidget widget;
+ QChronoTimer::singleShot(200ms, &widget, &MyWidget::updateCaption);
+//! [qchronotimer-singleshot]
+//! [zero-timer]
+ // The default interval is 0ns
+ QChronoTimer *timer = new QChronoTimer(this);
+ connect(timer, &QChronoTimer::timeout, this, &MyWidget::processOneThing);
+ timer->start();
+//! [zero-timer]
+
+ {
+//! [timer-interval-in-ctor]
+ QChronoTimer *timer = new QChronoTimer(1s, this);
+ connect(timer, &QChronoTimer::timeout, this, &MyWidget::processOneThing);
+ timer->start();
+//! [timer-interval-in-ctor]
+ }
+
+ {
+//! [timer-setinterval]
+ QChronoTimer *timer = new QChronoTimer(this);
+ connect(timer, &QChronoTimer::timeout, this, &MyWidget::processOneThing);
+ timer->setInterval(1s);
+ timer->start();
+//! [timer-setinterval]
+ }
+ }
+
+public Q_SLOTS:
+ void processOneThing();
+};
+
+int main()
+{
}
diff --git a/src/corelib/doc/src/animation.qdoc b/src/corelib/doc/src/animation.qdoc
index 28f88c907a..3d6c1eefa2 100644
--- a/src/corelib/doc/src/animation.qdoc
+++ b/src/corelib/doc/src/animation.qdoc
@@ -222,7 +222,7 @@
A QPropertyAnimation should always have a parent that controls
its lifespan. A typical application may include several animations that
are grouped, where the animation group takes ownership of those animations.
- An independent QProperyAnimation must be explicitly assigned a parent to
+ An independent QPropertyAnimation must be explicitly assigned a parent to
control its lifespan. In the following example, you can see that an
independent QPropertyAnimation has the QApplication instance as its
parent:
diff --git a/src/corelib/doc/src/cbor.qdoc b/src/corelib/doc/src/cbor.qdoc
index 22252bbd88..30d7ddaf60 100644
--- a/src/corelib/doc/src/cbor.qdoc
+++ b/src/corelib/doc/src/cbor.qdoc
@@ -6,6 +6,7 @@
\title CBOR Support in Qt
\ingroup qt-basic-concepts
\brief An overview of CBOR support in Qt.
+ \ingroup explanations-dataprocessingandio
\ingroup frameworks-technologies
@@ -35,7 +36,7 @@
In addition, CBOR can add a "tag" to extend the meaning of the type. The
container types can contain basic types, string-like types and containers.
- \sa {Cbordump Example}, {Convert Example}, {JSON Save Game Example}
+ \sa {Parsing and displaying CBOR data}, {Serialization Converter}, {Saving and Loading a Game}
\section1 The CBOR Classes
diff --git a/src/corelib/doc/src/cmake/cmake-commands.qdoc b/src/corelib/doc/src/cmake/cmake-commands.qdoc
index 7e98c16e41..e185bab624 100644
--- a/src/corelib/doc/src/cmake/cmake-commands.qdoc
+++ b/src/corelib/doc/src/cmake/cmake-commands.qdoc
@@ -4,6 +4,7 @@
/*!
\group cmake-commands-qtcore
\title CMake Commands in Qt6 Core
+\brief Lists CMake commands defined in Qt6::Core.
The following CMake commands are defined when Qt6::Core is loaded, for instance
with
diff --git a/src/corelib/doc/src/cmake/cmake-configure-variables.qdoc b/src/corelib/doc/src/cmake/cmake-configure-variables.qdoc
index 9653800bc8..8422a688f0 100644
--- a/src/corelib/doc/src/cmake/cmake-configure-variables.qdoc
+++ b/src/corelib/doc/src/cmake/cmake-configure-variables.qdoc
@@ -10,6 +10,7 @@
/*!
\group cmake-variables-qtcore
\title CMake Variables in Qt6 Core
+\brief Lists CMake variables defined in Qt6::Core.
The following CMake variables are defined when Qt6::Core is loaded, for instance
with
@@ -21,7 +22,7 @@ find_package(Qt6 REQUIRED COMPONENTS Core)
\sa{CMake Variable Reference}
*/
-*/*!
+/*!
\page cmake-variable-android-ndk-host-system-name.html
\ingroup cmake-variables-qtcore
@@ -34,7 +35,7 @@ find_package(Qt6 REQUIRED COMPONENTS Core)
\preliminarycmakevariable
\cmakevariableandroidonly
-This is normally set by the Android NDK toolchain file. It is written out as
+Usually, this variable is set by the Android NDK toolchain file. It is written out as
part of the deployment settings for a target.
\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()}
@@ -53,8 +54,8 @@ part of the deployment settings for a target.
\preliminarycmakevariable
\cmakevariableandroidonly
-This specifies the location of the Android SDK when building for the Android platform.
-It is written out as part of the deployment settings for a target.
+Specifies the location of the Android SDK when building for the Android platform.
+This variable is written out as part of the deployment settings for a target.
\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()}.
*/
@@ -62,6 +63,7 @@ It is written out as part of the deployment settings for a target.
/*!
\page cmake-variable-qt-android-application-arguments.html
\ingroup cmake-variables-qtcore
+\ingroup cmake-android-manifest-properties
\title QT_ANDROID_APPLICATION_ARGUMENTS
\target cmake-variable-QT_ANDROID_APPLICATION_ARGUMENTS
@@ -72,15 +74,122 @@ It is written out as part of the deployment settings for a target.
\preliminarycmakevariable
\cmakevariableandroidonly
-This contains a list of arguments to be passed to Android applications. It is written
-out as part of the deployment settings for a target.
+Contains a list of arguments to be passed to Android applications. This variable
+is written out as part of the deployment settings for a target.
\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()}
*/
/*!
+\page cmake-variable-qt-android-deployment-type.html
+\ingroup cmake-variables-qtcore
+\ingroup cmake-android-build-properties
+
+\title QT_ANDROID_DEPLOYMENT_TYPE
+\target cmake-variable-QT_ANDROID_DEPLOYMENT_TYPE
+
+\summary {Forces or disables release package signing regardless of the build type.}
+
+\cmakevariablesince 6.7
+\preliminarycmakevariable
+\cmakevariableandroidonly
+
+When set to \c Release, the \c --release flag is passed to the \c
+androiddeployqt tool, regardless of the application build type. When set to
+another value, the \c --release flag is never passed to the tool, which
+effectively disables release package signing even in Release or RelWithDebInfo
+builds. When not set, the default behavior is to use release package signing in
+build types other than Debug.
+
+\sa {androiddeployqt}
+*/
+
+/*!
+\page cmake_variable-qt-android-multi-abi-forward-vars
+\ingroup cmake-variables-qtcore
+\ingroup cmake-android-build-properties
+
+\title QT_ANDROID_MULTI_ABI_FORWARD_VARS
+\target cmake-variable-QT_ANDROID_MULTI_ABI_FORWARD_VARS
+
+\summary {Allows to share CMake variables in multi-ABI builds.}
+
+\cmakevariablesince 6.4.2
+\preliminarycmakevariable
+\cmakevariableandroidonly
+
+Allows specifying the list of
+CMake variables that need to be forwarded from the main ABI project to
+ABI-specific subprojects. Due to the specifics of the Multi-ABI project build
+process, there is no generic way to forward the CMake cache variables
+that are specified either in the command line or in another similar way.
+
+A typical use case for the variable is propagating CMake cache variables
+specified in the command line. For example, a project has two variables
+\c{PROJECT_WIDE_VARIABLE1} and \c{PROJECT_WIDE_VARIABLE2} that affect the
+project configuration:
+\badcode
+cmake_minimum_required(VERSION 3.18)
+
+project(MyProject LANGUAGES CXX)
+
+find_package(Qt6 REQUIRED COMPONENTS Core)
+
+qt_add_executable(MyApp main.cpp)
+
+if(PROJECT_WIDE_VARIABLE1)
+ target_sources(MyApp PRIVATE sourcefile1.cpp)
+endif()
+if(PROJECT_WIDE_VARIABLE2)
+ target_sources(MyApp PRIVATE sourcefile2.cpp)
+endif()
+\endcode
+
+The above contents of \c{CMakeLists.txt} enable you to control how
+\c{MyApp} is built by setting the corresponding CMake variables from the
+command line:
+\badcode
+qt-cmake -S<source directory> -B<build directory> \
+ -DPROJECT_WIDE_VARIABLE1=ON \
+ -DPROJECT_WIDE_VARIABLE2=ON \
+ -DQT_ANDROID_MULTI_ABI_FORWARD_VARS="PROJECT_WIDE_VARIABLE1;PROJECT_WIDE_VARIABLE2"
+\endcode
+
+When configuring the application for desktop, \c{PROJECT_WIDE_VARIABLE1} and
+\c{PROJECT_WIDE_VARIABLE2} are visible in CMake listings and scripts as global
+cache variables. This doesn't work for Android Multi-ABI builds because
+ABI-specific subprojects do not inherit the cache variables from the main-ABI
+project. This issue can be solved by passing the list of required variables to
+the \c{QT_ANDROID_MULTI_ABI_FORWARD_VARS} variable, so both
+\c{PROJECT_WIDE_VARIABLE1} and \c{PROJECT_WIDE_VARIABLE2} values will be
+propagated to the ABI-specific builds.
+
+The variable can be also defined in the project's CMakeLists.txt:
+\badcode
+...
+qt_add_executable(MyApp main.cpp)
+...
+if(ANDROID)
+ set(QT_ANDROID_MULTI_ABI_FORWARD_VARS "PROJECT_WIDE_VARIABLE1;PROJECT_WIDE_VARIABLE2")
+endif()
+...
+\endcode
+
+Set the variable in this way to have a predefined set of
+variables that will always be forwarded to ABI-specific projects.
+
+\note The forwarding is done in the target finalizer, which is implicitly
+called when \l{qt6_add_executable}{qt_add_executable()} is used. The
+finalization occurs automatically when using CMake 3.19 or later.
+
+\sa {qt6_finalize_target}{qt_finalize_target()},
+ {qt6_add_executable}{qt_add_executable()}
+*/
+
+/*!
\page cmake-variable-qt-android-build-all-abis.html
\ingroup cmake-variables-qtcore
+\ingroup cmake-android-build-properties
\title QT_ANDROID_BUILD_ALL_ABIS
\target cmake-variable-QT_ANDROID_BUILD_ALL_ABIS
@@ -91,7 +200,7 @@ out as part of the deployment settings for a target.
\preliminarycmakevariable
\cmakevariableandroidonly
-The option automatically detects available ABIs of Qt for Android and uses them to
+Automatically detects available ABIs of Qt for Android and uses them to
build a package. The automatic detection expects the default directory structure
supplied by the Qt installer, with the corresponding naming of the directories.
\include cmake-android-supported-abis.qdocinc
@@ -106,7 +215,7 @@ The typical directory structure looks as below:
\endcode
The auto-detected paths can be customized using one of \c{QT_PATH_ANDROID_ABI_<ABI>} variables.
-The variable is set to FALSE by default.
+The variable is set to \c FALSE by default.
\sa{QT_PATH_ANDROID_ABI_<ABI>}
*/
@@ -114,6 +223,7 @@ The variable is set to FALSE by default.
/*!
\page cmake-variable-qt-android-abis.html
\ingroup cmake-variables-qtcore
+\ingroup cmake-android-build-properties
\title QT_ANDROID_ABIS
\target cmake-variable-QT_ANDROID_ABIS
@@ -124,10 +234,10 @@ The variable is set to FALSE by default.
\preliminarycmakevariable
\cmakevariableandroidonly
-This variable specifies a list of ABIs to be used to build the project packages.
+Specifies a list of ABIs to be used to build the project packages.
\include cmake-android-supported-abis.qdocinc
Each ABI should have the corresponding Qt for Android either installed or
-user-built. It's possible to specify the path to the Qt for Android ABI using
+user-built. To specify the path to the Qt for Android ABI, use
the corresponding \c{QT_PATH_ANDROID_ABI_<ABI>} variable.
\note \c{QT_ANDROID_BUILD_ALL_ABIS} has the higher priority and ignores the
@@ -158,16 +268,17 @@ Each variable can be used to specify the path to Qt for Android for the correspo
/*!
\page cmake-variable-qt-android-sign-aab.html
\ingroup cmake-variables-qtcore
+\ingroup cmake-android-build-properties
\title QT_ANDROID_SIGN_AAB
\target cmake-variable-QT_ANDROID_SIGN_AAB
-\summary {Sign the .aab package with the specified keystore, alias and store password.}
+\summary {Signs the .aab package with the specified keystore, alias, and store password.}
\cmakevariablesince 6.4
\preliminarycmakevariable
\cmakevariableandroidonly
-Sign the resulting package. The path of the keystore file, the alias of the key and passwords
+Signs the resulting package. The path of the keystore file, the alias of the key, and passwords
have to be specified by additional environment variables:
\badcode
QT_ANDROID_KEYSTORE_PATH
@@ -175,7 +286,7 @@ have to be specified by additional environment variables:
QT_ANDROID_KEYSTORE_STORE_PASS
QT_ANDROID_KEYSTORE_KEY_PASS
\endcode
-Mentioned variables are used internally by \l{androiddeployqt}.
+The mentioned variables are used internally by \l{androiddeployqt}.
\sa{androiddeployqt}
*/
@@ -183,16 +294,17 @@ Mentioned variables are used internally by \l{androiddeployqt}.
/*!
\page cmake-variable-qt-android-sign-apk.html
\ingroup cmake-variables-qtcore
+\ingroup cmake-android-build-properties
\title QT_ANDROID_SIGN_APK
\target cmake-variable-QT_ANDROID_SIGN_APK
-\summary {Sign the package with the specified keystore, alias and store password.}
+\summary {Signs the package with the specified keystore, alias, and store password.}
\cmakevariablesince 6.4
\preliminarycmakevariable
\cmakevariableandroidonly
-Sign the resulting package. The path of the keystore file, the alias of the key and passwords
+Signs the resulting package. The path of the keystore file, the alias of the key, and passwords
have to be specified by additional environment variables:
\badcode
QT_ANDROID_KEYSTORE_PATH
@@ -200,12 +312,56 @@ have to be specified by additional environment variables:
QT_ANDROID_KEYSTORE_STORE_PASS
QT_ANDROID_KEYSTORE_KEY_PASS
\endcode
-Mentioned variables are used internally by \l{androiddeployqt}.
+The mentioned variables are used internally by \l{androiddeployqt}.
\sa{androiddeployqt}
*/
/*!
+\page cmake-variable-qt-android-generate-java-qml-components.html
+\ingroup cmake-variables-qtcore
+\ingroup cmake-android-build-properties
+
+\title QT_ANDROID_GENERATE_JAVA_QML_COMPONENTS
+\target cmake-variable-QT_ANDROID_GENERATE_JAVA_QML_COMPONENTS
+
+\summary {Enables the generation of QtQmlComponent-based classes.}
+\cmakevariablesince 6.8
+\preliminarycmakevariable
+\cmakevariableandroidonly
+
+This variable enables Java code generation for QML components of the target application. The
+generated code will be included in the resulting package. The Java package name of generated
+classes will be the same as the Android app package. If the leaf part of the package name is
+not the same as the target executable, an extra static class with the same name as the
+capitalized target executable will surround all QML modules enclosing Java classes. Each QML
+module class, again in a capitalized form, will contain QtQmlComponent extension classes that
+represent QML components of that module.
+*/
+
+\sa{androiddeployqt}
+/*!
+\page cmake-variable-qt-use-target-android-build-dir.html
+\ingroup cmake-variables-qtcore
+
+\title QT_USE_TARGET_ANDROID_BUILD_DIR
+\target cmake-variable-QT_USE_TARGET_ANDROID_BUILD_DIR
+
+\summary {Enables the use of per-target Android build directories.}
+
+\cmakevariablesince 6.7
+\preliminarycmakevariable
+\cmakevariableandroidonly
+
+The variable appends the target-specific suffix to the android-build directory.
+The variable only takes an effect when it's set in \c CACHE. The variable is
+only supported by Qt Creator starting from version 13.
+If a single \c CMakeLists.txt contains more than one Android executable and
+this option is not set, you will see a warning. To disable the warning, set
+\c QT_SKIP_ANDROID_BUILD_DIR_CHECK to \c TRUE.
+*/
+
+/*!
\page cmake-variable-qt-no-collect-build-tree-apk-deps.html
\ingroup cmake-variables-qtcore
@@ -222,7 +378,7 @@ During project finalization, the build system collects the locations of
all built shared library targets in the project.
These locations are passed to \l androiddeployqt for deployment consideration when
resolving dependencies between libraries.
-Set \c QT_NO_COLLECT_BUILD_TREE_APK_DEPS to \c TRUE to disable this behavior.
+To disable this behavior, set this variable to \c TRUE.
\sa {qt6_finalize_project}{qt_finalize_project()}
\sa {cmake-variable-QT_NO_COLLECT_IMPORTED_TARGET_APK_DEPS}{QT_NO_COLLECT_IMPORTED_TARGET_APK_DEPS}
@@ -243,12 +399,12 @@ Set \c QT_NO_COLLECT_BUILD_TREE_APK_DEPS to \c TRUE to disable this behavior.
When using CMake version 3.21 or later, the build system collects the locations of
imported shared library targets that might be relevant for deployment.
-The collected targets are those that are reachable from the the directory scope
+The collected targets are those that are reachable from the directory scope
of the currently processed executable target. That includes the target's source directory
scope and its parents.
The collected locations are passed to \l androiddeployqt for deployment consideration when
resolving dependencies between libraries.
-Set \c QT_NO_COLLECT_IMPORTED_TARGET_APK_DEPS to \c TRUE to disable this behavior.
+To disable this behavior, set this variable to \c TRUE.
\sa {qt6_finalize_project}{qt_finalize_project()}
\sa {cmake-variable-QT_NO_COLLECT_BUILD_TREE_APK_DEPS}{QT_NO_COLLECT_BUILD_TREE_APK_DEPS}
@@ -265,9 +421,12 @@ Set \c QT_NO_COLLECT_IMPORTED_TARGET_APK_DEPS to \c TRUE to disable this behavio
\cmakevariablesince 6.0
-When cross-compiling, this must be set to the install location of Qt for the host
+When cross-compiling, this variable must be set to the install location of Qt for the host
platform. It is used to locate tools to be run on the host (\l{moc}, \l{rcc},
-\l{androiddeployqt}, and so on).
+\l{androiddeployqt}, and so on). It's possible to reuse pre-installed tools
+when compiling Qt for host systems too, by using \c QT_HOST_PATH that points to
+a pre-installed host Qt and setting the \c QT_FORCE_FIND_TOOLS to \c ON. The Qt
+versions should match in this case.
*/
/*!
@@ -284,7 +443,7 @@ platform. It is used to locate tools to be run on the host (\l{moc}, \l{rcc},
When finalizing an executable target on iOS,
\l{qt6_finalize_target}{qt_finalize_target()} will populate the target's
\c XCODE_ATTRIBUTE_DEVELOPMENT_TEAM property if it hasn't been set.
-Set \c QT_NO_SET_XCODE_DEVELOPMENT_TEAM_ID to true if you want to prevent this.
+To prevent this, set \c QT_NO_SET_XCODE_DEVELOPMENT_TEAM_ID to \c TRUE.
*/
/*!
@@ -302,7 +461,7 @@ When finalizing an executable target on iOS,
\l{qt6_finalize_target}{qt_finalize_target()} will populate the target's
\c XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER and
\c MACOSX_BUNDLE_GUI_IDENTIFIER properties if they haven't been set.
-Set \c QT_NO_SET_XCODE_BUNDLE_IDENTIFIER to true if you want to prevent this.
+To prevent this, set \c QT_NO_SET_XCODE_BUNDLE_IDENTIFIER to \c TRUE.
*/
/*!
@@ -312,7 +471,7 @@ Set \c QT_NO_SET_XCODE_BUNDLE_IDENTIFIER to true if you want to prevent this.
\title QT_ENABLE_VERBOSE_DEPLOYMENT
\target cmake-variable-QT_ENABLE_VERBOSE_DEPLOYMENT
-\summary {Enables verbose mode of deployment tools}
+\summary {Enables verbose mode of deployment tools.}
\cmakevariablesince 6.3
\preliminarycmakevariable
@@ -321,7 +480,7 @@ Enables verbose mode of the \l androiddeployqt deployment tool when it is called
internally at build time, usually during target finalization.
This variable also changes the default verbosity of install-time deployment
-scripts for other platforms (see \l{qt_deploy_runtime_dependencies()}), but it
+scripts for other platforms (see \l{qt6_deploy_runtime_dependencies()}), but it
must be set before the first \c{find_package(Qt6)} call to have that effect.
*/
@@ -341,15 +500,16 @@ must be set before the first \c{find_package(Qt6)} call to have that effect.
This configure-phase variable is set by the Core package. It is intended to be
used as the first line of any deployment script to ensure access to the
deployment APIs provided by Qt. Such deployment scripts do not run during
-CMake's configure phase, they are executed during installation or as
+CMake's configure phase. They are executed during installation or as
part of a post-build rule.
The following example shows one way the variable would be used when installing
an application, along with its runtime dependencies:
-\include cmake-deploy-runtime-dependencies.qdocinc
+\include cmake-deploy-modified-variable-values.qdocinc
-\sa qt_deploy_runtime_dependencies(), qt_deploy_qml_imports()
+\sa {qt6_deploy_runtime_dependencies}{qt_deploy_runtime_dependencies()},
+ {qt6_deploy_qml_imports}{qt_deploy_qml_imports()}
*/
/*!
@@ -365,24 +525,79 @@ an application, along with its runtime dependencies:
The \l{qt6_standard_project_setup}{qt_standard_project_setup()} command is
typically called in the top level \c{CMakeLists.txt} file of a project. In some
-scenarios, such projects may be absorbed as a child project of a larger project
+scenarios, such a project may be absorbed as a child project of a larger project
hierarchy. A parent project may want to prevent any child project from applying
changes to the setup. The parent project can achieve this by setting
-\c{QT_NO_STANDARD_PROJECT_SETUP} to true before bringing in the child project
-via \l{add_subdirectory()}, \l{FetchContent_MakeAvailable()} or other similar
+\c{QT_NO_STANDARD_PROJECT_SETUP} to \c TRUE before bringing in the child project
+via \l{add_subdirectory()}, \l{FetchContent_MakeAvailable()}, or other similar
methods provided by CMake.
\sa {qt6_standard_project_setup}{qt_standard_project_setup()}
*/
/*!
+\page cmake-variable-qt-i18n-languages.html
+\ingroup cmake-variables-qtcore
+
+\title QT_I18N_TRANSLATED_LANGUAGES
+\target cmake-variable-QT_I18N_TRANSLATED_LANGUAGES
+
+\summary {List of languages to be used for project internationalization.}
+
+\cmakevariablesince 6.7
+
+Specifies a list of languages that are used for project
+internationalization. The single languages must be compatible with the
+string-based \l QLocale constructor.
+
+The languages in \c QT_I18N_TRANSLATED_LANGUAGES are used to:
+\list
+ \li Set up executable targets for consuming \c{.qm} files.
+ \li Automatically construct \c{.ts} file names in
+ \l{qt6_add_translations}{qt_add_translations()}.
+\endlist
+
+This variable can be conveniently set with the
+\l {qt6_standard_project_setup}{qt_standard_project_setup()} command.
+
+By default, translatable strings are considered to be written in \c{en}.
+
+\sa {qt6_standard_project_setup}{qt_standard_project_setup()}
+\sa {qt6_add_translations}{qt_add_translations()}
+*/
+
+/*!
+\page cmake-variable-qt-i18n-native-language.html
+\ingroup cmake-variables-qtcore
+
+\title QT_I18N_SOURCE_LANGUAGE
+\target cmake-variable-QT_I18N_SOURCE_LANGUAGE
+
+\summary {Specifies the language of translatable strings.}
+
+\cmakevariablesince 6.7
+
+Specifies the language of translatable strings in the source code.
+The language must be compatible with the string-based \l QLocale constructor.
+
+Together with \c{QT_I18N_TRANSLATED_LANGUAGES}, this variable is used to determine the
+names of \c{.ts} files for \l{qt6_add_translations}{qt_add_translations()}.
+
+This variable can be conveniently set with the
+\l {qt6_standard_project_setup}{qt_standard_project_setup()} command.
+
+\sa {qt6_standard_project_setup}{qt_standard_project_setup()}
+\sa {qt6_add_translations}{qt_add_translations()}
+*/
+
+/*!
\page cmake-variable-qt-ios-launch-screen.html
\ingroup cmake-variables-qtcore
\title QT_IOS_LAUNCH_SCREEN
\target cmake-variable-QT_IOS_LAUNCH_SCREEN
-\summary {Path to iOS launch screen storyboard used by all targets}
+\summary {Path to iOS launch screen storyboard used by all targets.}
\cmakevariablesince 6.4
\preliminarycmakevariable
diff --git a/src/corelib/doc/src/cmake/cmake-deploy-variables.qdoc b/src/corelib/doc/src/cmake/cmake-deploy-variables.qdoc
index a84b9bca6e..ac5094e7cb 100644
--- a/src/corelib/doc/src/cmake/cmake-deploy-variables.qdoc
+++ b/src/corelib/doc/src/cmake/cmake-deploy-variables.qdoc
@@ -19,7 +19,6 @@
\include cmake-deploy-var-usage.qdocinc
\cmakevariablesince 6.3
-\preliminarycmakevariable
\c{QT_DEPLOY_PREFIX} provides the base deployment directory. The other
\c{QT_DEPLOY_..._DIR} variables should be treated as relative to this location.
@@ -48,8 +47,9 @@ scripts should assume that the working directory is already set to the base
install location and just use the prefix-relative \c{QT_DEPLOY_..._DIR}
variables.
-\sa QT_DEPLOY_SUPPORT, QT_DEPLOY_BIN_DIR, QT_DEPLOY_LIB_DIR,
- QT_DEPLOY_PLUGINS_DIR, QT_DEPLOY_QML_DIR, QT_DEPLOY_TRANSLATIONS_DIR
+\sa QT_DEPLOY_SUPPORT, QT_DEPLOY_BIN_DIR, QT_DEPLOY_LIBEXEC_DIR,
+ QT_DEPLOY_LIB_DIR, QT_DEPLOY_PLUGINS_DIR, QT_DEPLOY_QML_DIR,
+ QT_DEPLOY_TRANSLATIONS_DIR
*/
/*!
@@ -64,7 +64,6 @@ variables.
\include cmake-deploy-var-usage.qdocinc
\cmakevariablesince 6.3
-\preliminarycmakevariable
Projects should use \c QT_DEPLOY_BIN_DIR in their deploy scripts to avoid
hard-coding a particular directory in which to deploy the following types of
@@ -89,7 +88,46 @@ should not be used for that scenario.
\include cmake-deploy-runtime-dependencies.qdocinc
-\sa QT_DEPLOY_SUPPORT, QT_DEPLOY_PREFIX, QT_DEPLOY_LIB_DIR,
+\sa QT_DEPLOY_SUPPORT, QT_DEPLOY_PREFIX, QT_DEPLOY_LIBEXEC_DIR,
+ QT_DEPLOY_LIB_DIR, QT_DEPLOY_PLUGINS_DIR, QT_DEPLOY_QML_DIR,
+ QT_DEPLOY_TRANSLATIONS_DIR
+*/
+
+/*!
+\page cmake-variable-qt-deploy-libexec-dir.html
+\ingroup cmake-variables-qtcore
+
+\title QT_DEPLOY_LIBEXEC_DIR
+\target cmake-variable-QT_DEPLOY_LIBEXEC_DIR
+
+\summary {Prefix-relative subdirectory for deploying program executables on some target platforms.}
+
+\include cmake-deploy-var-usage.qdocinc
+
+\cmakevariablesince 6.7
+
+On Unix derivatives, projects should use \c QT_DEPLOY_LIBEXEC_DIR in their
+deploy scripts to avoid hard-coding a particular directory in which to deploy
+helper executables that are local to the project.
+
+For example, projects using QtWebEngine would deploy the \c QtWebEngineProcess
+executable to this directory.
+
+\c QT_DEPLOY_LIBEXEC_DIR defaults to the value of \c${CMAKE_INSTALL_LIBEXECDIR}
+(usually \c{libexec}), which is provided by CMake's \l{GNUInstallDirs} module.
+To change the value of \c QT_DEPLOY_LIBEXEC_DIR, ensure that the project sets
+\c{CMAKE_INSTALL_LIBEXECDIR} before the \c Core package is found.
+
+The \c QT_DEPLOY_LIBEXEC_DIR path is relative to \l{QT_DEPLOY_PREFIX}.
+
+This variable is not meaningful when deploying into a macOS app bundle and
+should not be used for that scenario.
+
+\section1 Example
+
+\include cmake-deploy-modified-variable-values.qdocinc
+
+\sa QT_DEPLOY_SUPPORT, QT_DEPLOY_PREFIX, QT_DEPLOY_BIN_DIR, QT_DEPLOY_LIB_DIR,
QT_DEPLOY_PLUGINS_DIR, QT_DEPLOY_QML_DIR, QT_DEPLOY_TRANSLATIONS_DIR
*/
@@ -105,7 +143,6 @@ should not be used for that scenario.
\include cmake-deploy-var-usage.qdocinc
\cmakevariablesince 6.3
-\preliminarycmakevariable
Projects should use \c QT_DEPLOY_LIB_DIR in their deploy scripts to avoid
hard-coding a particular directory in which to deploy the following types of
@@ -147,7 +184,6 @@ should not be used for that scenario.
\include cmake-deploy-var-usage.qdocinc
\cmakevariablesince 6.3
-\preliminarycmakevariable
Projects should use \c QT_DEPLOY_PLUGINS_DIR in their deploy scripts to avoid
hard-coding a particular directory under which to deploy plugins.
@@ -167,8 +203,9 @@ bundle contents.
\include cmake-deploy-modified-variable-values.qdocinc
-\sa QT_DEPLOY_SUPPORT, QT_DEPLOY_PREFIX, QT_DEPLOY_BIN_DIR, QT_DEPLOY_LIB_DIR,
- QT_DEPLOY_QML_DIR, QT_DEPLOY_TRANSLATIONS_DIR
+\sa QT_DEPLOY_SUPPORT, QT_DEPLOY_PREFIX, QT_DEPLOY_BIN_DIR,
+ QT_DEPLOY_LIBEXEC_DIR, QT_DEPLOY_LIB_DIR, QT_DEPLOY_QML_DIR,
+ QT_DEPLOY_TRANSLATIONS_DIR
*/
/*!
@@ -183,7 +220,6 @@ bundle contents.
\include cmake-deploy-var-usage.qdocinc
\cmakevariablesince 6.3
-\preliminarycmakevariable
Projects should use \c QT_DEPLOY_QML_DIR in their deploy scripts to avoid
hard-coding a particular directory under which to deploy QML modules.
@@ -205,8 +241,9 @@ to be deployed to different locations within the app bundle.
\include cmake-deploy-modified-variable-values.qdocinc
-\sa QT_DEPLOY_SUPPORT, QT_DEPLOY_PREFIX, QT_DEPLOY_BIN_DIR, QT_DEPLOY_LIB_DIR,
- QT_DEPLOY_PLUGINS_DIR, QT_DEPLOY_TRANSLATIONS_DIR
+\sa QT_DEPLOY_SUPPORT, QT_DEPLOY_PREFIX, QT_DEPLOY_BIN_DIR,
+ QT_DEPLOY_LIBEXEC_DIR, QT_DEPLOY_LIB_DIR, QT_DEPLOY_PLUGINS_DIR,
+ QT_DEPLOY_TRANSLATIONS_DIR
*/
/*!
@@ -221,7 +258,6 @@ to be deployed to different locations within the app bundle.
\include cmake-deploy-var-usage.qdocinc
\cmakevariablesince 6.5
-\preliminarycmakevariable
Projects should use \c QT_DEPLOY_TRANSLATIONS_DIR in their deploy scripts to
avoid hard-coding a particular directory under which to deploy translations.
@@ -239,7 +275,7 @@ This variable is not meaningful when deploying on macOS or Windows.
\include cmake-deploy-modified-variable-values.qdocinc
\sa QT_DEPLOY_SUPPORT, QT_DEPLOY_PREFIX, QT_DEPLOY_BIN_DIR, QT_DEPLOY_LIB_DIR,
- QT_DEPLOY_PLUGINS_DIR, QT_DEPLOY_QML_DIR
+ QT_DEPLOY_LIBEXEC_DIR, QT_DEPLOY_PLUGINS_DIR, QT_DEPLOY_QML_DIR
*/
/*!
@@ -254,7 +290,6 @@ This variable is not meaningful when deploying on macOS or Windows.
\include cmake-deploy-var-usage.qdocinc
\cmakevariablesince 6.5
-\preliminarycmakevariable
This variable contains a list of directories that are not taken into account
when searching for runtime dependencies with \l{qt_deploy_runtime_dependencies}.
diff --git a/src/corelib/doc/src/cmake/cmake-properties.qdoc b/src/corelib/doc/src/cmake/cmake-properties.qdoc
index 3ade73b56b..4b602d5d07 100644
--- a/src/corelib/doc/src/cmake/cmake-properties.qdoc
+++ b/src/corelib/doc/src/cmake/cmake-properties.qdoc
@@ -4,6 +4,7 @@
/*!
\group cmake-target-properties-qtcore
\title CMake Target Properties in Qt6 Core
+\brief Lists CMake target properties known to Qt6::Core.
\l{CMake Commands in Qt6 Core}{CMake Commands} know about the following CMake
target properties:
@@ -15,6 +16,7 @@ target properties:
\page cmake-target-property-qt-android-deployment-dependencies.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
+\ingroup cmake-android-build-properties
\title QT_ANDROID_DEPLOYMENT_DEPENDENCIES
\target cmake-target-property-QT_ANDROID_DEPLOYMENT_DEPENDENCIES
@@ -46,6 +48,7 @@ is listed before its dependencies, it will fail to load on some devices.
\page cmake-target-property-qt-android-extra-libs.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
+\ingroup cmake-android-build-properties
\title QT_ANDROID_EXTRA_LIBS
\target cmake-target-property-QT_ANDROID_EXTRA_LIBS
@@ -61,6 +64,56 @@ A list of external libraries that will be copied into your application's
to enable OpenSSL in your application. For more information, see
\l{Adding OpenSSL Support for Android}.
+When adding extra libraries from the build tree of your project, it's also
+necessary to add dependency relations between library and the application
+target. Using the following project structure may cause an issue, when deploying
+an apk:
+\badcode
+qt_add_executable(MyApp main.cpp)
+
+set_target_properties(MyApp PROPERTIES
+ QT_ANDROID_EXTRA_LIBS
+ ${CMAKE_CURRENT_BINARY_DIR}/libMyService_${ANDROID_ABI}.so
+)
+
+# MyService library doesn't have any relations with MyApp
+qt_add_library(MyService service.cpp)
+\endcode
+
+This leads to uncertainty whether MyService library will be available before
+the deployment of MyApp or not. The easiest solution is adding MyService
+library to the MyApp dependencies:
+\badcode
+add_dependencies(MyApp MyService)
+\endcode
+
+When adding per-architecture libraries to a multi-abi project,
+list all their paths explicitly, rather than rely on variables like
+\c CMAKE_ANDROID_ARCH_ABI to dynamically compute the paths.
+
+Prefer:
+
+\badcode
+set(libs
+ ${CMAKE_CURRENT_BINARY_DIR}/libA_x86so
+ ${CMAKE_CURRENT_BINARY_DIR}/libA_x86_64.so
+ ${CMAKE_CURRENT_BINARY_DIR}/libA_arm64-v8a.so
+ ${CMAKE_CURRENT_BINARY_DIR}/libA_armeabi-v7a.so
+)
+set_target_properties(MyApp PROPERTIES QT_ANDROID_EXTRA_LIBS ${libs})
+
+# When targeting precompiled libs
+target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC libA_${ANDROID_ABI})
+\endcode
+
+over:
+
+\badcode
+set_target_properties(MyApp PROPERTIES
+ QT_ANDROID_EXTRA_LIBS
+ ${CMAKE_CURRENT_BINARY_DIR}/libA_${CMAKE_ANDROID_ARCH_ABI}.so)
+\endcode
+
\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()}
*/
@@ -68,6 +121,7 @@ to enable OpenSSL in your application. For more information, see
\page cmake-target-property-qt-android-extra-plugins.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
+\ingroup cmake-android-build-properties
\title QT_ANDROID_EXTRA_PLUGINS
\target cmake-target-property-QT_ANDROID_EXTRA_PLUGINS
@@ -99,6 +153,7 @@ mangling is applied to the plugin library.
\page cmake-target-property-qt-android-min-sdk-version.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
+\ingroup cmake-android-build-properties
\title QT_ANDROID_MIN_SDK_VERSION
\target cmake-target-property-QT_ANDROID_MIN_SDK_VERSION
@@ -118,6 +173,7 @@ Specifies the minimum Android API level for the target.
\page cmake-target-property-qt-android-package-source-dir.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
+\ingroup cmake-android-build-properties
\title QT_ANDROID_PACKAGE_SOURCE_DIR
\target cmake-target-property-QT_ANDROID_PACKAGE_SOURCE_DIR
@@ -151,6 +207,7 @@ then place this directly into the directory specified by this variable.
\page cmake-target-property-qt-android-target-sdk-version.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
+\ingroup cmake-android-build-properties
\title QT_ANDROID_TARGET_SDK_VERSION
\target cmake-target-property-QT_ANDROID_TARGET_SDK_VERSION
@@ -167,12 +224,84 @@ Specifies the target Android API level for the target.
*/
/*!
+\page cmake-target-property-qt-android-sdk-build-tools-revision.html
+\ingroup cmake-properties-qtcore
+\ingroup cmake-target-properties-qtcore
+\ingroup cmake-android-build-properties
+
+\title QT_ANDROID_SDK_BUILD_TOOLS_REVISION
+\target cmake-target-property-QT_ANDROID_SDK_BUILD_TOOLS_REVISION
+
+\summary {Revision of Android build tools to use.}
+
+\cmakepropertysince 6.0
+\preliminarycmakeproperty
+\cmakepropertyandroidonly
+
+Specifies the Android SDK build tools revision to use. If this is not set then
+CMake will attempt to use the latest installed version.
+
+\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()}
+*/
+
+/*!
+\page cmake-target-property-qt-android-package-name.html
+\ingroup cmake-properties-qtcore
+\ingroup cmake-target-properties-qtcore
+\ingroup cmake-android-build-properties
+
+\title QT_ANDROID_PACKAGE_NAME
+\target cmake-target-property-QT_ANDROID_PACKAGE_NAME
+
+\summary {The app's package name.}
+
+\cmakepropertysince 6.8
+\preliminarycmakeproperty
+\cmakepropertyandroidonly
+
+Specifies the app's package name. This is usually a unique dot separated
+name for the app, that will be used to identify the app on devices or in
+the Play Store. For example, "org.qtproject.example.gallery".
+
+The package name set by this property is passed to the \c build.gradle file
+as a \c namespace property, instead of \c AndroidManifest.xml, since the
+latter is deprecated since Android Gradle Plugin 7.4.
+
+The package name considers some words or characters as illegal and the build
+will clean such names if any is encountered. An underscore (\c _) either replaces
+illegal characters or is appended to illegal words.
+
+\list
+ \li Allowed characters: alphanumeric, an underscore or a dot [a-zA-Z0-9_.].
+ \li Illegal words: abstract, continue, for, new, switch, assert, default,
+ if, package, synchronized, boolean, do, goto, private, this, break,
+ double, implements, protected, throw, byte, else, import, public,
+ throws, case, enum, instanceof, return, transient, catch, extends,
+ int, short, try, char, final, interface, static, void, class, finally,
+ long, strictfp, volatile, const, float, native, super, while.
+\endlist
+
+The default package name for Qt for Android apps is \c org.qtproject.example.<target_name>.
+
+\note Setting the package name manually in \c build.gradle (via
+\c namespace property) takes precedence over \c AndroidManifest.xml
+(via \c package attribute), and the latter also takes precedence over
+this property.
+
+For more information, see Android's
+\l{Android: Configure the app module}{configure the app module}.
+
+\sa{qt6_android_generate_deployment_settings}{qt_android_generate_deployment_settings()}
+*/
+
+/*!
\page cmake-target-property-qt-android-version-code.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
\title QT_ANDROID_VERSION_CODE
\target cmake-target-property-QT_ANDROID_VERSION_CODE
+\ingroup cmake-android-manifest-properties
\summary {Internal Android app version.}
@@ -195,6 +324,7 @@ For more information, see \l{Android: App Versioning}{Android App Versioning}.
\title QT_ANDROID_VERSION_NAME
\target cmake-target-property-QT_ANDROID_VERSION_NAME
+\ingroup cmake-android-manifest-properties
\summary {Human-readable Android app version.}
@@ -214,6 +344,7 @@ For more information, see \l{Android: App Versioning}{Android App Versioning}.
\page cmake-target-property-qt-android-abis.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
+\ingroup cmake-android-build-properties
\title QT_ANDROID_ABIS
\target cmake-target-property-QT_ANDROID_ABIS
@@ -280,6 +411,7 @@ For application-specific QML imports, use
\page cmake-target-property-qt-android-deployment-settings-file.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
+\ingroup cmake-android-build-properties
\title QT_ANDROID_DEPLOYMENT_SETTINGS_FILE
\target cmake-target-property-QT_ANDROID_DEPLOYMENT_SETTINGS_FILE
@@ -300,6 +432,7 @@ and overwritten by that command.
\page cmake-target-property-qt-android-system-libs-prefix.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
+\ingroup cmake-android-build-properties
\title QT_ANDROID_SYSTEM_LIBS_PREFIX
\target cmake-target-property-QT_ANDROID_SYSTEM_LIBS_PREFIX
@@ -317,6 +450,7 @@ when those libraries are installed outside app's native (JNI) library directory.
\page cmake-target-property-qt-android-no-deploy-qt-libs.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
+\ingroup cmake-android-build-properties
\title QT_ANDROID_NO_DEPLOY_QT_LIBS
\target cmake-target-property-QT_ANDROID_NO_DEPLOY_QT_LIBS
@@ -375,6 +509,7 @@ resource prefix.
/*!
\group cmake-source-file-properties-qtcore
\title CMake Source File Properties in Qt6 Core
+\brief Lists CMake file properties used in Qt6::Core.
\l{CMake Commands in Qt6 Core}{CMake Commands} know about the following CMake
source file properties:
@@ -392,7 +527,6 @@ source file properties:
\summary {Specifies the Qt resource alias for a file in a resource.}
\cmakepropertysince 6.0
-\preliminarycmakeproperty
When using the target-based variant of \l{qt6_add_resources}{qt_add_resources}
the property value overrides the runtime path where the resource file is found.
@@ -401,6 +535,33 @@ the property value overrides the runtime path where the resource file is found.
*/
/*!
+\page cmake-source-file-property-qt-discard-file-contents.html
+\ingroup cmake-source-file-properties-qtcore
+
+\title QT_DISCARD_FILE_CONTENTS
+\target cmake-source-file-property-QT_DISCARD_FILE_CONTENTS
+
+\summary {Specifies that the given files should be empty in the resource file system}
+
+\cmakepropertysince 6.6
+\preliminarycmakeproperty
+
+When using the target-based variant of \l{qt6_add_resources}{qt_add_resources}
+or \l{qt_add_qml_module}, setting this property to \c TRUE causes the file
+contents to be omitted when creating the resource file system. The file name is
+retained.
+
+This is useful if you want to strip QML source code from the binary.
+
+\note If you omit the QML source code from the binary, the QML engine has to
+rely on the compilation units created by \l{qmlcachegen} or \l{qmlsc}.
+Those are tied to the specific version of Qt they were built with. If you change
+the version of Qt your application uses, they can't be loaded anymore.
+
+\sa{The Qt Resource System}
+*/
+
+/*!
\page cmake-target-property-qt-wasm-pthread-pool-size.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
@@ -427,6 +588,7 @@ For more information, see \l{https://emscripten.org/docs/porting/pthreads.html}{
/*!
\group cmake-global-properties-qtcore
\title CMake Global Properties in Qt6 Core
+\brief Lists CMake global properties used or defined in Qt6::Core.
\l{CMake Commands in Qt6 Core}{CMake Commands} know about the following global
CMake properties:
@@ -483,6 +645,29 @@ For more information, see \l{https://github.com/emscripten-core/emscripten/blob/
*/
/*!
+\page cmake-target-property-qt-wasm-maximum-memory.html
+\ingroup cmake-properties-qtcore
+\ingroup cmake-target-properties-qtcore
+
+\title QT_WASM_MAXIMUM_MEMORY
+\target cmake-target-property-QT_WASM_MAXIMUM_MEMORY
+
+\summary {Internal WebAssembly maximum memory.}
+
+\cmakepropertysince 6.7
+\preliminarycmakeproperty
+\cmakepropertywebassemblyonly
+
+Specifies the maximum amount of memory the application can use. Translates into
+the Emscripten compiler setting of \c MAXIMUM_MEMORY. The default value
+is 4GB, which is the maximum for 32-bit WebAssembly.
+
+For more information, see the \l{https://github.com/emscripten-core/emscripten/blob/3319a313d3b589624d342b650884caaf8cd9ef30/src/settings.js#L187}{Emscripten compiler settings}.
+*/
+
+
+
+/*!
\page cmake-target-property-qt-ios-launch-screen.html
\ingroup cmake-properties-qtcore
\ingroup cmake-target-properties-qtcore
diff --git a/src/corelib/doc/src/cmake/cmake-standard-properties.qdoc b/src/corelib/doc/src/cmake/cmake-standard-properties.qdoc
new file mode 100644
index 0000000000..a8ece6ba8f
--- /dev/null
+++ b/src/corelib/doc/src/cmake/cmake-standard-properties.qdoc
@@ -0,0 +1,24 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+\page cmake-standard-property-autogen-better-graph-multi-config.html
+\ingroup cmake-standard-properties
+
+\title AUTOGEN_BETTER_GRAPH_MULTI_CONFIG
+
+\brief Improves the dependency graph for multi-configuration generators when you
+set it on a target.
+
+When this boolean property is enabled, \c{CMake} will generate more per-config targets.
+Thus, the dependency graph will be more accurate for multi-configuration
+generators and some recompilations will be avoided.
+
+Since Qt 6.8, this property is enabled by default. For older versions,
+you need to enable it manually to use it.
+However, \l{qt_extract_metatypes} and \l{qt_add_qml_module} were updated to
+support \c{AUTOGEN_BETTER_GRAPH_MULTI_CONFIG} in Qt 6.8, so you will get build
+errors, unless you patch the older Qt version to support it.
+
+See \l{https://cmake.org/cmake/help/latest/prop_tgt/AUTOGEN_BETTER_GRAPH_MULTI_CONFIG.html}{AUTOGEN_BETTER_GRAPH_MULTI_CONFIG} for more information.
+*/
diff --git a/src/corelib/doc/src/cmake/policy/qtp0002.qdoc b/src/corelib/doc/src/cmake/policy/qtp0002.qdoc
new file mode 100644
index 0000000000..a40344a167
--- /dev/null
+++ b/src/corelib/doc/src/cmake/policy/qtp0002.qdoc
@@ -0,0 +1,63 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+\page qt-cmake-policy-qtp0002.html
+\ingroup qt-cmake-policies
+
+\title QTP0002
+\keyword qt_cmake_policy_qtp0002
+
+\summary {Target properties that specify Android-specific paths may contain generator expressions.}
+
+This policy was introduced in Qt 6.6. It changes the processing of target
+properties that specify Android-specific paths:
+\list
+ \li \l QT_QML_IMPORT_PATH
+ \li \l QT_QML_ROOT_PATH
+ \li \l QT_ANDROID_PACKAGE_SOURCE_DIR
+ \li \l QT_ANDROID_EXTRA_PLUGINS
+ \li \l QT_ANDROID_EXTRA_LIBS
+\endlist
+
+The \c OLD behavior of this policy doesn't allow generator expressions in the
+target properties that specify Android-specific paths but implicitly converts
+the specified paths to valid JSON strings.
+
+The \c NEW behavior of this policy allows using generator expressions in the
+target properties that specify Android-specific paths, but they must evaluate to
+valid JSON strings.
+
+The following value of the \l QT_ANDROID_EXTRA_PLUGINS property is converted to
+a valid JSON string if you set the policy to OLD, but leads to an error if the
+policy is set to NEW:
+\badcode
+set_target_properties(
+ QT_ANDROID_EXTRA_PLUGINS "\\path\\to\\MyPlugin.so"
+)
+\endcode
+If the policy is set to NEW for the above example, the resulting JSON string in
+the deployment settings file will contain escaped symbols instead of path
+separators.
+
+Generator expressions are only supported if the policy is set to NEW, so the
+OLD behavior generates a malformed deployment settings file with the following
+code:
+\badcode
+set_target_properties(
+ QT_ANDROID_EXTRA_PLUGINS "$<TARGET_FILE_DIR:MyPlugin>"
+)
+\endcode
+
+This property value works as expected with both OLD and NEW policy values:
+\badcode
+set_target_properties(
+ QT_ANDROID_EXTRA_PLUGINS "/path/to/MyPlugin.so"
+)
+\endcode
+
+\qtpolicydeprecatedbehavior
+
+\sa qt_policy, {Qt CMake policies}
+
+*/
diff --git a/src/corelib/doc/src/cmake/policy/qtp0003.qdoc b/src/corelib/doc/src/cmake/policy/qtp0003.qdoc
new file mode 100644
index 0000000000..bf11b6f8b5
--- /dev/null
+++ b/src/corelib/doc/src/cmake/policy/qtp0003.qdoc
@@ -0,0 +1,46 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+\page qt-cmake-policy-qtp0003.html
+\ingroup qt-cmake-policies
+\since 6.7
+\title QTP0003
+\keyword qt_cmake_policy_qtp0003
+
+\summary {Consider the BUILD_SHARED_LIBS value when creating Qt libraries.}
+
+This policy was introduced in Qt 6.7. The policy affects the default type of the
+libraries created using \l {CMake Commands in Qt6 Core}{Qt CMake API}, like
+\l {qt_add_library}, \l{qt_add_plugin}, \l{qt_add_qml_module}.
+
+If the policy is set to \c OLD, the default library type that is selected is
+aligned with the Qt build type, either \c shared or \c static.
+
+If the policy is set to \c NEW, the library type is selected according to the
+\l {CMake BUILD_SHARED_LIBS Documentation}{BUILD_SHARED_LIBS} value if it's set.
+If \c BUILD_SHARED_LIBS is not set, the default library type falls back to the
+Qt build type.
+
+For example, the following code will use the Qt build type as the default
+library type for the \c MyLib target, despite the fact \c BUILD_SHARED_LIBS is
+set to \c ON:
+\badcode
+set(BUILD_SHARED_LIBS ON)
+...
+qt6_add_library(MyLib sourcefile.h sourcefile.cpp)
+\endcode
+
+If you set the QTP0003 to \c NEW before the \l {qt6_add_library}{qt_add_library}
+call, \c BUILD_SHARED_LIBS will affect the library default type and \c MyLib
+will be the shared library.
+\badcode
+set(BUILD_SHARED_LIBS ON)
+...
+qt_policy(SET QTP0003 NEW)
+qt6_add_library(MyLib sourcefile.h sourcefile.cpp)
+\endcode
+
+\sa qt_policy, {Qt CMake policies}, qt_add_library
+
+*/
diff --git a/src/corelib/doc/src/cmake/qt_add_big_resources.qdoc b/src/corelib/doc/src/cmake/qt_add_big_resources.qdoc
index 72a00e6eef..8215d4c717 100644
--- a/src/corelib/doc/src/cmake/qt_add_big_resources.qdoc
+++ b/src/corelib/doc/src/cmake/qt_add_big_resources.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_add_big_resources
-\target qt6_add_big_resources
+\keyword qt6_add_big_resources
\summary {Compiles big binary resources into object code.}
diff --git a/src/corelib/doc/src/cmake/qt_add_binary_resources.qdoc b/src/corelib/doc/src/cmake/qt_add_binary_resources.qdoc
index 71ee8b894e..12ee5e1aff 100644
--- a/src/corelib/doc/src/cmake/qt_add_binary_resources.qdoc
+++ b/src/corelib/doc/src/cmake/qt_add_binary_resources.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_add_binary_resources
-\target qt6_add_binary_resources
+\keyword qt6_add_binary_resources
\summary {Creates an RCC file from a list of Qt resource files.}
diff --git a/src/corelib/doc/src/cmake/qt_add_executable.qdoc b/src/corelib/doc/src/cmake/qt_add_executable.qdoc
index 6bdc6000e8..cc8c924c79 100644
--- a/src/corelib/doc/src/cmake/qt_add_executable.qdoc
+++ b/src/corelib/doc/src/cmake/qt_add_executable.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_add_executable
-\target qt6_add_executable
+\keyword qt6_add_executable
\summary {Creates and finalizes an application target of a platform-specific type.}
@@ -110,5 +110,5 @@ for finalizing the target by adding the \c{MANUAL_FINALIZATION} keyword.
\snippet cmake-macros/examples.cmake qt_add_executable_deferred
-\include cmake-android-qt-finalize-project-warning.qdocinc
+\include cmake-android-qt-finalize-project-warning.qdocinc warning
*/
diff --git a/src/corelib/doc/src/cmake/qt_add_library.qdoc b/src/corelib/doc/src/cmake/qt_add_library.qdoc
index 6a5d17f0f9..851a2d6210 100644
--- a/src/corelib/doc/src/cmake/qt_add_library.qdoc
+++ b/src/corelib/doc/src/cmake/qt_add_library.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_add_library
-\target qt6_add_library
+\keyword qt6_add_library
\summary {Creates and finalizes a library.}
@@ -45,8 +45,10 @@ library type created depends on how Qt was built. If Qt was built statically,
a static library will be created. Otherwise, a shared library will
be created. Note that this is different to how CMake's \c{add_library()}
command works, where the \c BUILD_SHARED_LIBS variable controls the type of
-library created. The \c{qt_add_library()} command does not consider
-\c BUILD_SHARED_LIBS when deciding the library type.
+library created.
+Since 6.7, the \c{qt_add_library()} command considers \c BUILD_SHARED_LIBS
+when deciding the library type only if the variable is set explicitly and
+\l {QTP0003} is set to \c NEW.
Any \c{sources} provided will be passed through to the internal call to
\c{add_library()}.
@@ -73,6 +75,6 @@ time. In general, \c MANUAL_FINALIZATION should not be needed unless the
project has to support CMake 3.18 or earlier.
\sa {qt6_finalize_target}{qt_finalize_target()},
- {qt6_add_executable}{qt_add_executable()}
+ {qt6_add_executable}{qt_add_executable()}, QTP0003
*/
diff --git a/src/corelib/doc/src/cmake/qt_add_plugin.qdoc b/src/corelib/doc/src/cmake/qt_add_plugin.qdoc
index 4341e22efb..d2322086e7 100644
--- a/src/corelib/doc/src/cmake/qt_add_plugin.qdoc
+++ b/src/corelib/doc/src/cmake/qt_add_plugin.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_add_plugin
-\target qt6_add_plugin
+\keyword qt6_add_plugin
\summary {Creates a Qt plugin target.}
@@ -26,6 +26,9 @@ qt_add_plugin(target
)
\endcode
+The \c MANUAL_FINALIZATION option and the ability to set sources
+were introduced in Qt 6.5.
+
\versionlessCMakeCommandsNote qt6_add_plugin()
\section1 Description
diff --git a/src/corelib/doc/src/cmake/qt_add_resources.qdoc b/src/corelib/doc/src/cmake/qt_add_resources.qdoc
index 982cf207af..2e713b1b8e 100644
--- a/src/corelib/doc/src/cmake/qt_add_resources.qdoc
+++ b/src/corelib/doc/src/cmake/qt_add_resources.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_add_resources
-\target qt6_add_resources
+\keyword qt6_add_resources
\summary {Compiles binary resources into source code.}
@@ -48,8 +48,6 @@ When passing a target as first argument, the function creates a resource with
the name \c{RESOURCE_NAME}, containing the specified \c{FILES}. The resource is
automatically linked into \c{TARGET}.
-For embedding bigger resources, see \l qt_add_big_resources.
-
See \l{The Qt Resource System} for a general description of Qt resources.
\section1 Arguments of the target-based variant
@@ -107,4 +105,6 @@ resources linked into the final target.
This especially affects static builds. There, the same resource name in
different static libraries conflict in the consuming target.
+
+\sa {qt6_add_big_resources}{qt_add_big_resources()}
*/
diff --git a/src/corelib/doc/src/cmake/qt_allow_non_utf8_sources.qdoc b/src/corelib/doc/src/cmake/qt_allow_non_utf8_sources.qdoc
index 617baa0109..ad95401f4d 100644
--- a/src/corelib/doc/src/cmake/qt_allow_non_utf8_sources.qdoc
+++ b/src/corelib/doc/src/cmake/qt_allow_non_utf8_sources.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_allow_non_utf8_sources
-\target qt6_allow_non_utf8_sources
+\keyword qt6_allow_non_utf8_sources
\summary {Prevents forcing source files to be treated as UTF-8 for Windows.}
diff --git a/src/corelib/doc/src/cmake/qt_android_add_apk_target.qdoc b/src/corelib/doc/src/cmake/qt_android_add_apk_target.qdoc
index 747849eabb..b2415730f5 100644
--- a/src/corelib/doc/src/cmake/qt_android_add_apk_target.qdoc
+++ b/src/corelib/doc/src/cmake/qt_android_add_apk_target.qdoc
@@ -6,14 +6,14 @@
\ingroup cmake-commands-qtcore
\title qt_android_add_apk_target
-\target qt6_android_add_apk_target
+\keyword qt6_android_add_apk_target
\summary {Defines a build target that runs androiddeployqt to produce an APK.}
\include cmake-find-package-core.qdocinc
\cmakecommandsince 6.0
-\preliminarycmakecommand
+\warning This command is deprecated since Qt 6.5. Use \l qt_add_executable instead.
\cmakecommandandroidonly
\section1 Synopsis
diff --git a/src/corelib/doc/src/cmake/qt_android_apply_arch_suffix.qdoc b/src/corelib/doc/src/cmake/qt_android_apply_arch_suffix.qdoc
index 4d4585693d..a29e1f6123 100644
--- a/src/corelib/doc/src/cmake/qt_android_apply_arch_suffix.qdoc
+++ b/src/corelib/doc/src/cmake/qt_android_apply_arch_suffix.qdoc
@@ -6,14 +6,15 @@
\ingroup cmake-commands-qtcore
\title qt_android_apply_arch_suffix
-\target qt6_android_apply_arch_suffix
+\keyword qt6_android_apply_arch_suffix
\summary {Configures the target binary's name to include an architecture-specific suffix.}
\include cmake-find-package-core.qdocinc
\cmakecommandsince 6.0
-\preliminarycmakecommand
+\warning This command is deprecated since Qt 6.5. Use \l qt_add_executable
+or \l qt_add_library instead.
\cmakecommandandroidonly
\section1 Synopsis
diff --git a/src/corelib/doc/src/cmake/qt_android_generate_deployment_settings.qdoc b/src/corelib/doc/src/cmake/qt_android_generate_deployment_settings.qdoc
index a717c80e7c..daa3680070 100644
--- a/src/corelib/doc/src/cmake/qt_android_generate_deployment_settings.qdoc
+++ b/src/corelib/doc/src/cmake/qt_android_generate_deployment_settings.qdoc
@@ -6,14 +6,14 @@
\ingroup cmake-commands-qtcore
\title qt_android_generate_deployment_settings
-\target qt6_android_generate_deployment_settings
+\keyword qt6_android_generate_deployment_settings
\summary {Generates the deployment settings file needed by androiddeployqt.}
\include cmake-find-package-core.qdocinc
\cmakecommandsince 6.0
-\preliminarycmakecommand
+\warning This command is deprecated since Qt 6.5. Use \l qt_add_executable instead.
\cmakecommandandroidonly
\section1 Synopsis
@@ -63,6 +63,7 @@ how to accomplish this.
\li \l{cmake-target-property-QT_ANDROID_MIN_SDK_VERSION}{QT_ANDROID_MIN_SDK_VERSION}
\li \l{cmake-target-property-QT_ANDROID_PACKAGE_SOURCE_DIR}{QT_ANDROID_PACKAGE_SOURCE_DIR}
\li \l{cmake-target-property-QT_ANDROID_TARGET_SDK_VERSION}{QT_ANDROID_TARGET_SDK_VERSION}
+\li \l{cmake-target-property-QT_ANDROID_PACKAGE_NAME}{QT_ANDROID_PACKAGE_NAME}
\li \l{cmake-target-property-QT_ANDROID_VERSION_NAME}{QT_ANDROID_VERSION_NAME}
\li \l{cmake-target-property-QT_ANDROID_VERSION_CODE}{QT_ANDROID_VERSION_CODE}
\li \l{cmake-target-property-QT_QML_IMPORT_PATH}{QT_QML_IMPORT_PATH}
diff --git a/src/corelib/doc/src/cmake/qt_deploy_qt_conf.qdoc b/src/corelib/doc/src/cmake/qt_deploy_qt_conf.qdoc
index fb3ee4796e..45fd8f4c5f 100644
--- a/src/corelib/doc/src/cmake/qt_deploy_qt_conf.qdoc
+++ b/src/corelib/doc/src/cmake/qt_deploy_qt_conf.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_deploy_qt_conf
-\target qt_deploy_qt_conf
+\keyword qt6_deploy_qt_conf
\summary {Write a qt.conf file at deployment time.}
@@ -17,7 +17,6 @@ only be called from a deployment script. It cannot be called directly by the
project.
\cmakecommandsince 6.3
-\preliminarycmakecommand
\note This command does not usually need to be called directly. It is used
internally by other higher level commands, but projects wishing to
implement more customized deployment logic may find it useful.
@@ -58,14 +57,14 @@ variables can be used to dynamically specify a path relative to the deployment b
as shown in the example below. This helps avoid hard-coding an absolute path.
\sa {qt6_generate_deploy_app_script}{qt_generate_deploy_app_script()},
- qt_deploy_runtime_dependencies()
+ {qt6_deploy_runtime_dependencies}{qt_deploy_runtime_dependencies()}
\section1 Example
\badcode
# The following script must only be executed at install time
qt_generate_deploy_script(
- FILENAME_VARIABLE deploy_script
+ OUTPUT_SCRIPT deploy_script
CONTENT "
qt_deploy_qt_conf(\"\${QT_DEPLOY_PREFIX}/\${QT_DEPLOY_BIN_DIR}/qt.conf\"
DATA_DIR \"./custom_data_dir\"
diff --git a/src/corelib/doc/src/cmake/qt_deploy_runtime_dependencies.qdoc b/src/corelib/doc/src/cmake/qt_deploy_runtime_dependencies.qdoc
index 7f6198d804..f64960492a 100644
--- a/src/corelib/doc/src/cmake/qt_deploy_runtime_dependencies.qdoc
+++ b/src/corelib/doc/src/cmake/qt_deploy_runtime_dependencies.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_deploy_runtime_dependencies
-\target qt_deploy_runtime_dependencies
+\keyword qt6_deploy_runtime_dependencies
\summary {Deploy Qt plugins, Qt and non-Qt libraries needed by an executable.}
@@ -17,7 +17,6 @@ can only be called from a deployment script. It cannot be called directly by the
project during the configure stage.
\cmakecommandsince 6.3
-\preliminarycmakecommand
\note This command does not usually need to be called directly. It is used
internally by other higher level commands, but projects wishing to
implement more customized deployment logic may find it useful.
@@ -32,6 +31,7 @@ qt_deploy_runtime_dependencies(
[ADDITIONAL_MODULES files...]
[GENERATE_QT_CONF]
[BIN_DIR bin_dir]
+ [LIBEXEC_DIR libexec_dir]
[LIB_DIR lib_dir]
[PLUGINS_DIR plugins_dir]
[QML_DIR qml_dir]
@@ -39,6 +39,8 @@ qt_deploy_runtime_dependencies(
[NO_OVERWRITE]
[NO_APP_STORE_COMPLIANCE]
[NO_TRANSLATIONS]
+ [NO_COMPILER_RUNTIME]
+ [DEPLOY_TOOL_OPTIONS]
[PRE_INCLUDE_REGEXES regexes...]
[PRE_EXCLUDE_REGEXES regexes...]
[POST_INCLUDE_REGEXES regexes...]
@@ -54,12 +56,16 @@ When installing an application, it may be desirable to also install the
libraries and plugins it depends on. When the application is a macOS app bundle
or a Windows executable, \c{qt_deploy_runtime_dependencies()} can be called
from an install-time script to deploy those dependencies. It will install
-non-system libraries (both Qt and those provided by the project), plus an
-appropriate set of Qt plugins.
+non-system Qt libraries plus an appropriate set of Qt plugins.
+
+On Linux, the command will deploy additional libraries, beyond just those
+related to Qt, that are included with the project. However, when executed on
+macOS or Windows, the command will use either \c macdeployqt or \c windeployqt,
+which will only deploy libraries that are specific to Qt.
This command only considers runtime dependencies for which linking
relationships exist in the underlying binaries. It does not deploy QML modules,
-see \l{qt_deploy_qml_imports()} for that.
+see \l{qt6_deploy_qml_imports}{qt_deploy_qml_imports()} for that.
\section1 Arguments
@@ -98,13 +104,41 @@ directory structure. If the \c{GENERATE_QT_CONF} option is given, an appropriate
\c{qt.conf} file will be written to the same directory as the \c{executable}.
The paths in that \c{qt.conf} file will be based on the \c{CMAKE_INSTALL_xxxDIR}
variables, whose defaults are provided by CMake's \l{GNUInstallDirs} module.
-You can override some of those defaults with the \c{BIN_DIR}, \c{LIB_DIR},
-\c{PLUGINS_DIR}, and \c{QML_DIR} options, all of which are expected to be
-relative to the base install location. A \c{qt.conf} file is always written if
-\c{executable} is a macOS app bundle, regardless of whether or not
-\c{GENERATE_QT_CONF} is provided. The \c{..._DIR} options are also ignored in
-that case, since the directory layout of an app bundle is dictated by Apple's
-requirements.
+
+You can override some of those defaults with the parameters in the following
+table, all of which are expected to be relative to the base install location.
+
+\table
+\header
+ \li parameter
+ \li affected variable
+ \li notes
+\row
+ \li \c BIN_DIR
+ \li \l QT_DEPLOY_BIN_DIR
+ \li
+\row
+ \li \c LIBEXEC_DIR
+ \li \l QT_DEPLOY_LIBEXEC_DIR
+ \li since Qt 6.7
+\row
+ \li \c LIB_DIR
+ \li \l QT_DEPLOY_LIB_DIR
+ \li
+\row
+ \li \c PLUGINS_DIR
+ \li \l QT_DEPLOY_PLUGINS_DIR
+ \li
+\row
+ \li \c QML_DIR
+ \li \l QT_DEPLOY_QML_DIR
+ \li
+\endtable
+
+A \c{qt.conf} file is always written if \c{executable} is a macOS app bundle,
+regardless of whether or not \c{GENERATE_QT_CONF} is provided. The \c{..._DIR}
+options are also ignored in that case, since the directory layout of an app
+bundle is dictated by Apple's requirements.
More verbose output about the deployment steps can be enabled by providing the
\c{VERBOSE} option. Alternatively, the \l{QT_ENABLE_VERBOSE_DEPLOYMENT}
@@ -122,8 +156,15 @@ libraries that comply with Apple's app store requirements are deployed. The
On platforms other than macOS, Qt translations are automatically deployed. To
inhibit this behavior, specify \c{NO_TRANSLATIONS}. Use
-\l{qt6_deploy_translations}{qt_deploy_translations} to deploy translations in a
-customized way.
+\l{qt6_deploy_translations}{qt_deploy_translations()} to deploy translations
+in a customized way.
+
+For Windows desktop applications, the required runtime files for the compiler
+are also installed by default. To prevent this, specify \c{NO_COMPILER_RUNTIME}.
+
+Since Qt 6.7, you can use \c{DEPLOY_TOOL_OPTIONS} to pass additional options to
+the underlying deployment tool. This only has an effect if the underlying
+deployment tool is either macdeployqt or windeployqt.
On Linux, deploying runtime dependencies is based on CMake's
\c{file(GET_RUNTIME_DEPENDENCIES)} command. The options \c{PRE_INCLUDE_REGEXES},
@@ -140,9 +181,18 @@ The default value of \c{POST_EXCLUDE_REGEXES} is constructed from the value of
\l{QT_DEPLOY_IGNORED_LIB_DIRS}.
\sa {qt6_generate_deploy_app_script}{qt_generate_deploy_app_script()},
- qt_deploy_qt_conf(), qt_deploy_qml_imports()
+ {qt6_deploy_qt_conf}{qt_deploy_qt_conf()},
+ {qt6_deploy_qml_imports}{qt_deploy_qml_imports()}
\section1 Example
+The following example shows how to deploy an application \c{MyApp}.
+
\include cmake-deploy-runtime-dependencies.qdocinc
+
+The following example shows how to use the \c{DEPLOY_TOOL_OPTIONS} parameter to
+pass different options to macdeployqt and windeployqt.
+
+\include cmake-deploy-runtime-dependencies-deploy-tool-options.qdocinc
+
*/
diff --git a/src/corelib/doc/src/cmake/qt_deploy_translations.qdoc b/src/corelib/doc/src/cmake/qt_deploy_translations.qdoc
index 7d175fd651..43ff23a35a 100644
--- a/src/corelib/doc/src/cmake/qt_deploy_translations.qdoc
+++ b/src/corelib/doc/src/cmake/qt_deploy_translations.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_deploy_translations
-\target qt_deploy_translations
+\keyword qt6_deploy_translations
\summary {Deploy Qt translations needed by an executable.}
@@ -58,7 +58,7 @@ that is used in the project via \c{find_package}.
The \c LCONVERT argument specifies the \c lconvert executable that is used to
combine the catalogs. By default, the Qt installation's \c lconvert is used.
-For debugging purposed, the \c VERBOSE argument can be set to turn on diagnostic
+For debugging purposes, the \c VERBOSE argument can be set to turn on diagnostic
messages.
\sa QT_DEPLOY_TRANSLATIONS_DIR
diff --git a/src/corelib/doc/src/cmake/qt_disable_unicode_defines.qdoc b/src/corelib/doc/src/cmake/qt_disable_unicode_defines.qdoc
index f4ad3c6426..91de52544e 100644
--- a/src/corelib/doc/src/cmake/qt_disable_unicode_defines.qdoc
+++ b/src/corelib/doc/src/cmake/qt_disable_unicode_defines.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_disable_unicode_defines
-\target qt6_disable_unicode_defines
+\keyword qt6_disable_unicode_defines
\summary {Prevents some unicode-related compiler definitions being set automatically on a target.}
diff --git a/src/corelib/doc/src/cmake/qt_extract_metatypes.qdoc b/src/corelib/doc/src/cmake/qt_extract_metatypes.qdoc
index 837baa3f0c..7ec8d90f9b 100644
--- a/src/corelib/doc/src/cmake/qt_extract_metatypes.qdoc
+++ b/src/corelib/doc/src/cmake/qt_extract_metatypes.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_extract_metatypes
-\target qt6_extract_metatypes
+\keyword qt6_extract_metatypes
\summary {Extracts metatypes from a Qt target and generates an associated metatypes.json file.}
@@ -52,4 +52,18 @@ example, to pass it to another command or to install it), use the
\c OUTPUT_FILES option to provide the name of a variable in which to store its
absolute path.
+\section1 Automatic metatype extraction
+
+Since Qt 6.8, if you have not disabled \c{AUTOMOC} and either are using CMake
+3.19 or later or are calling \l{qt6_finalize_target}{qt_finalize_target()}
+manually, then \c{qt_extract_metatypes()} is automatically called as part of the
+finalization step for \l{qt_add_library}. This has no effect if you have
+manually called \c{qt_extract_metatypes()} before the finalization, possibly
+with custom arguments. However, it does make sure that the metatypes are also
+produced if you haven't. This is important if any of the types in the library
+are used as part of any QML types any time in the future and has no downsides.
+
+Furthermore, \l{qt_add_qml_module} automatically invokes
+\c{qt_extract_metatypes()} for its target.
+
*/
diff --git a/src/corelib/doc/src/cmake/qt_finalize_project.qdoc b/src/corelib/doc/src/cmake/qt_finalize_project.qdoc
index 56ab40055c..5506712691 100644
--- a/src/corelib/doc/src/cmake/qt_finalize_project.qdoc
+++ b/src/corelib/doc/src/cmake/qt_finalize_project.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_finalize_project
-\target qt6_finalize_project
+\keyword qt6_finalize_project
\summary {Handles various common platform-specific tasks associated with a Qt project.}
\preliminarycmakecommand
@@ -38,7 +38,7 @@ With CMake version 3.19 or later, you don't need to call this command since
it consists of sub-commands that are ordinarily invoked at the end of
\c CMAKE_SOURCE_DIR directory scope processing.
-\include cmake-android-qt-finalize-project-warning.qdocinc
+\include cmake-android-qt-finalize-project-warning.qdocinc warning
\section2 Examples
diff --git a/src/corelib/doc/src/cmake/qt_finalize_target.qdoc b/src/corelib/doc/src/cmake/qt_finalize_target.qdoc
index 4b71248a1e..b74dee64d2 100644
--- a/src/corelib/doc/src/cmake/qt_finalize_target.qdoc
+++ b/src/corelib/doc/src/cmake/qt_finalize_target.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_finalize_target
-\target qt6_finalize_target
+\keyword qt6_finalize_target
\summary {Handles various common platform-specific tasks associated with Qt targets.}
@@ -32,10 +32,10 @@ was created, so this command should also be called from that same directory
scope.
This command is ordinarily invoked as part of a call to
-\l{qt6_add_executable}{qt_add_executable()} or
-\l{qt6_add_library}{qt_add_library()}. The timing of when that call takes
-place and when it might need to be called explicitly by a project is discussed
-in the documentation of those commands.
+\l{qt6_add_executable}{qt_add_executable()},
+\l{qt6_add_library}{qt_add_library()}, or \l{qt6_add_plugin}{qt_add_plugin()}.
+The timing of when that call takes place and when a project might need to call
+it explicitly, is discussed in the documentation of those commands.
\sa {qt6_set_finalizer_mode}{qt_set_finalizer_mode()}
diff --git a/src/corelib/doc/src/cmake/qt_generate_deploy_app_script.qdoc b/src/corelib/doc/src/cmake/qt_generate_deploy_app_script.qdoc
index 6f6f96b8ae..31d9e4384b 100644
--- a/src/corelib/doc/src/cmake/qt_generate_deploy_app_script.qdoc
+++ b/src/corelib/doc/src/cmake/qt_generate_deploy_app_script.qdoc
@@ -6,24 +6,25 @@
\ingroup cmake-commands-qtcore
\title qt_generate_deploy_app_script
-\target qt6_generate_deploy_app_script
+\keyword qt6_generate_deploy_app_script
\summary {Generate a deployment script for an application.}
\include cmake-find-package-core.qdocinc
\cmakecommandsince 6.3
-\preliminarycmakecommand
-\note This command is currently only supported on Windows and macOS.
+\note This command is currently only supported on Windows, macOS, and Linux.
\section1 Synopsis
\badcode
qt_generate_deploy_app_script(
TARGET target
- FILENAME_VARIABLE var_name
+ OUTPUT_SCRIPT <var>
[NO_TRANSLATIONS]
+ [NO_COMPILER_RUNTIME]
[NO_UNSUPPORTED_PLATFORM_ERROR]
+ [DEPLOY_TOOL_OPTIONS ...]
[PRE_INCLUDE_REGEXES regexes...]
[PRE_EXCLUDE_REGEXES regexes...]
[POST_INCLUDE_REGEXES regexes...]
@@ -48,14 +49,14 @@ determined by \l{GNUInstallDirs} (except for macOS app bundles, which follow
Apple's requirements instead).
The command generates a script whose name will be stored in the variable named
-by the \c{FILENAME_VARIABLE} option. That script is only written at CMake
+by the \c{OUTPUT_SCRIPT} option. That script is only written at CMake
generation time. It is intended to be used with the \l{install(SCRIPT)} command,
which should come after the application's target has been installed using
\l{install(TARGETS)}.
-The deployment script will call \l{qt_deploy_runtime_dependencies()} with a
-suitable set of options for the standard install layout.
-Currently, this is only implemented for
+The deployment script will call \l{qt6_deploy_runtime_dependencies}
+{qt_deploy_runtime_dependencies()} with a suitable set of options for the standard
+install layout. Currently, this is only implemented for
\list
\li macOS app bundles built on a macOS host,
\li Linux executables built on a Linux host,
@@ -68,9 +69,16 @@ in a fatal error, unless the \c{NO_UNSUPPORTED_PLATFORM_ERROR} option is given.
On platforms other than macOS, Qt translations are automatically deployed. To
inhibit this behavior, specify \c{NO_TRANSLATIONS}. Use
-\l{qt6_deploy_translations}{qt_deploy_translations} to deploy translations in a
+\l{qt6_deploy_translations}{qt_deploy_translations()} to deploy translations in a
customized way.
+For Windows desktop applications, the required runtime files for the compiler
+are also installed by default. To prevent this, specify \c{NO_COMPILER_RUNTIME}.
+
+Since Qt 6.7, you can use \c{DEPLOY_TOOL_OPTIONS} to pass additional options to
+the underlying deployment tool. This only has an effect if the underlying
+deployment tool is either macdeployqt or windeployqt.
+
For deploying a QML application, use
\l{qt6_generate_deploy_qml_app_script}{qt_generate_deploy_qml_app_script()}
instead.
@@ -82,7 +90,7 @@ The options \c{PRE_INCLUDE_REGEXES}, \c{PRE_EXCLUDE_REGEXES},
\c{POST_INCLUDE_REGEXES}, \c{POST_EXCLUDE_REGEXES}, \c{POST_INCLUDE_FILES}, and
\c{POST_EXCLUDE_FILES} can be specified to control the deployment of runtime
dependencies. These options do not apply to all platforms and are forwarded
-unmodified to \l{qt_deploy_runtime_dependencies()}.
+unmodified to \l{qt6_deploy_runtime_dependencies}{qt_deploy_runtime_dependencies()}.
\sa {qt6_standard_project_setup}{qt_standard_project_setup()},
{qt6_generate_deploy_script}{qt_generate_deploy_script()},
@@ -90,25 +98,13 @@ unmodified to \l{qt_deploy_runtime_dependencies()}.
\section1 Example
-\badcode
-cmake_minimum_required(VERSION 3.16...3.22)
-project(MyThings)
+The following example shows how to deploy an application \c{MyApp}.
-find_package(Qt6 REQUIRED COMPONENTS Core)
-qt_standard_project_setup()
+\include cmake-generate-deploy-app-script.qdocinc
-qt_add_executable(MyApp main.cpp)
+The following example shows how to use the \c{DEPLOY_TOOL_OPTIONS} parameter to
+pass different options to macdeployqt and windeployqt.
-install(TARGETS MyApp
- BUNDLE DESTINATION .
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
-)
+\include cmake-generate-deploy-app-script-deploy-tool-options.qdocinc
-qt_generate_deploy_app_script(
- TARGET MyApp
- FILENAME_VARIABLE deploy_script
- NO_UNSUPPORTED_PLATFORM_ERROR
-)
-install(SCRIPT ${deploy_script})
-\endcode
*/
diff --git a/src/corelib/doc/src/cmake/qt_generate_deploy_script.qdoc b/src/corelib/doc/src/cmake/qt_generate_deploy_script.qdoc
index af0a6956d1..eb8ed402a9 100644
--- a/src/corelib/doc/src/cmake/qt_generate_deploy_script.qdoc
+++ b/src/corelib/doc/src/cmake/qt_generate_deploy_script.qdoc
@@ -6,20 +6,19 @@
\ingroup cmake-commands-qtcore
\title qt_generate_deploy_script
-\target qt6_generate_deploy_script
+\keyword qt6_generate_deploy_script
\summary {Generate a custom deployment script.}
\include cmake-find-package-core.qdocinc
\cmakecommandsince 6.5
-\preliminarycmakecommand
\section1 Synopsis
\badcode
qt_generate_deploy_script(
- FILENAME_VARIABLE var_name
+ OUTPUT_SCRIPT <var>
[TARGET target]
[NAME script_name]
[CONTENT content]
@@ -31,7 +30,7 @@ qt_generate_deploy_script(
\section1 Description
The command generates a script whose full file path will be stored in the
-variable named by the \c{FILENAME_VARIABLE} option. That script is only written
+variable named by the \c{OUTPUT_SCRIPT} option. That script is only written
at CMake generation time. It is intended to be used with the \l{install(SCRIPT)}
command, which should come after the application's target has been installed
using \l{install(TARGETS)}.
diff --git a/src/corelib/doc/src/cmake/qt_generate_moc.qdoc b/src/corelib/doc/src/cmake/qt_generate_moc.qdoc
index 55b6df9e7d..9b123f9323 100644
--- a/src/corelib/doc/src/cmake/qt_generate_moc.qdoc
+++ b/src/corelib/doc/src/cmake/qt_generate_moc.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_generate_moc
-\target qt6_generate_moc
+\keyword qt6_generate_moc
\summary {Calls moc on an input file.}
diff --git a/src/corelib/doc/src/cmake/qt_import_plugins.qdoc b/src/corelib/doc/src/cmake/qt_import_plugins.qdoc
index b9606654b0..1f81a21cd2 100644
--- a/src/corelib/doc/src/cmake/qt_import_plugins.qdoc
+++ b/src/corelib/doc/src/cmake/qt_import_plugins.qdoc
@@ -6,9 +6,9 @@
\ingroup cmake-commands-qtcore
\title qt_import_plugins
-\target qt6_import_plugins
+\keyword qt6_import_plugins
-\summary {Specifies a custom set of plugins to import for a static Qt build.}
+\summary {Specifies a custom set of plugins to import or exclude.}
\include cmake-find-package-core.qdocinc
@@ -48,17 +48,35 @@ can be used more than once.
Qt provides plugin types such as \c imageformats, \c platforms,
and \c sqldrivers.
+\section2 Dynamic plugins
+
+If plugins are dynamic libraries, the function controls the plugin deployment.
+Using this function, you may exclude specific plugin types from
+being packaged into an Android APK, for example:
+
+\badcode
+qt_add_executable(MyApp ...)
+...
+qt_import_plugins(MyApp EXCLUDE_BY_TYPE imageformats)
+\endcode
+
+In the snippet above, all plugins that have the \c imageformats type will
+be excluded when deploying \c MyApp. The resulting Android APK will not
+contain any of the \c imageformats plugins.
+
+If the command isn't used, the target automatically deploys all plugins that
+belong to the Qt modules that the target is linked against.
+
+\section2 Static plugins
+
If the command isn't used the target automatically links against
-a sane set of default plugins, for each Qt module that the target is linked
-against. For more information, see
+a sane set of default static plugins, for each Qt module that the target is
+linked against. For more information, see
\l{CMake target_link_libraries Documentation}{target_link_libraries}.
Each plugin comes with a C++ stub file that automatically
-initializes the plugin. Consequently, any target that links against a plugin
-has this C++ file added to its \c SOURCES.
-
-\note This command imports plugins from static Qt builds only.
-On shared builds, it does nothing.
+initializes the static plugin. Consequently, any target that links against
+a plugin has this C++ file added to its \c SOURCES.
\section1 Examples
diff --git a/src/corelib/doc/src/cmake/qt_policy.qdoc b/src/corelib/doc/src/cmake/qt_policy.qdoc
new file mode 100644
index 0000000000..6deb7a729c
--- /dev/null
+++ b/src/corelib/doc/src/cmake/qt_policy.qdoc
@@ -0,0 +1,65 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+\page qt-policy.html
+\ingroup cmake-commands-qtcore
+
+\title qt_policy
+\keyword qt6_policy
+
+\summary {Modify the default behavior of Qt's CMake API.}
+
+\include cmake-find-package-core.qdocinc
+
+\cmakecommandsince 6.5
+
+\section1 Synopsis
+
+\badcode
+qt_policy(
+ [SET <policy_name> behavior]
+ [GET <policy_name> <variable>]
+)
+\endcode
+
+\versionlessCMakeCommandsNote qt6_policy()
+
+\section1 Description
+
+This command has two modes:
+
+\list
+\li When the \c{SET} keyword is used, this command can be used to opt in to
+ behavior changes in Qt's CMake API, or to explicitly opt out of them.
+\li When the \c{GET} keyword is used, \c{<variable>} is set to the current
+ behavior for the policy, i.e. \c OLD or \c NEW.
+\endlist
+
+\c{<policy_name>} must be the name of one of the \l{Qt CMake policies}.
+Policy names have the form of \c{QTP<NNNN>} where <NNNN> is
+an integer specifying the index of the policy. Using an invalid policy
+name results in an error.
+
+Code supporting older Qt versions can check the existence of a policy by
+checking the value of the \c{QT_KNOWN_POLICY_<policy_name>} variable before
+getting the value of \c <policy_name> or setting its behavior.
+
+\badcode
+if(QT_KNOWN_POLICY_<policy_name>)
+ qt_policy(SET <policy_name> NEW)
+endif()
+\endcode
+
+You can set \c behavior to one of the following options:
+
+\list
+\li \c{NEW} to opt into the new behavior
+\li \c{OLD} to explicitly opt-out of it
+\endlist
+
+\qtpolicydeprecatedbehavior
+
+\sa qt_standard_project_setup
+
+*/
diff --git a/src/corelib/doc/src/cmake/qt_set_finalizer_mode.qdoc b/src/corelib/doc/src/cmake/qt_set_finalizer_mode.qdoc
index f44a217544..28622c11e8 100644
--- a/src/corelib/doc/src/cmake/qt_set_finalizer_mode.qdoc
+++ b/src/corelib/doc/src/cmake/qt_set_finalizer_mode.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_set_finalizer_mode
-\target qt6_set_finalizer_mode
+\keyword qt6_set_finalizer_mode
\summary {Customizes aspects of a target's finalization.}
diff --git a/src/corelib/doc/src/cmake/qt_standard_project_setup.qdoc b/src/corelib/doc/src/cmake/qt_standard_project_setup.qdoc
index 6e91779fb9..59b33f599c 100644
--- a/src/corelib/doc/src/cmake/qt_standard_project_setup.qdoc
+++ b/src/corelib/doc/src/cmake/qt_standard_project_setup.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_standard_project_setup
-\target qt6_standard_project_setup
+\keyword qt6_standard_project_setup
\summary {Setup project-wide defaults to a standard arrangement.}
@@ -17,7 +17,12 @@
\section1 Synopsis
\badcode
-qt_standard_project_setup()
+qt_standard_project_setup(
+ [REQUIRES <version>]
+ [SUPPORTS_UP_TO <version>]
+ [I18N_TRANSLATED_LANGUAGES <language...>]
+ [I18N_SOURCE_LANGUAGE <language>]
+)
\endcode
\versionlessCMakeCommandsNote qt6_standard_project_setup()
@@ -42,11 +47,20 @@ have been defined. It does the following things:
\c{${CMAKE_CURRENT_BINARY_DIR}}.
\li When target platforms other than Apple or Windows, \c{CMAKE_INSTALL_RPATH}
will be augmented as described below.
-\li CMake's \l USE_FOLDERS property is set to \c{ON}, and \l QT_TARGET_FOLDER is
+\li CMake's \l USE_FOLDERS property is set to \c{ON}, and \l QT_TARGETS_FOLDER is
set to \c{QtInternalTargets}. IDEs that support folders will display
Qt-internal targets in this folder.
\endlist
+Since Qt 6.5, it is possible to change the default behavior of Qt's CMake
+API by opting in to changes from newer Qt versions. If \c{REQUIRES} is
+specified, all suggested changes introduced in Qt up to \c{REQUIRES} are enabled,
+and using an older Qt version will result in an error.
+If additionally \c{SUPPORTS_UP_TO} has been specified, any new changes introduced
+in versions up to \c{SUPPORTS_UP_TO} are also enabled (but using an older Qt
+version is not an error). This is similar to CMake's policy concept
+(compare \l{cmake_policy}).
+
On platforms that support \c{RPATH} (other than Apple platforms), two values
are appended to the \c{CMAKE_INSTALL_RPATH} variable by this command.
\c{$ORIGIN} is appended so that libraries will find other libraries they depend
@@ -67,8 +81,21 @@ The \c{qt_standard_project_setup()} command can effectively be disabled by
setting the \l{QT_NO_STANDARD_PROJECT_SETUP} variable to true.
\sa {qt6_generate_deploy_app_script}{qt_generate_deploy_app_script()}
+\sa qt_policy
+
+\section1 Internationalization
+
+Since Qt 6.7, it is possible to specify the languages that are used for project
+internationalization with the \c I18N_TRANSLATED_LANGUAGES argument. See \l
+QT_I18N_TRANSLATED_LANGUAGES for details.
+
+Use I18N_SOURCE_LANGUAGE to specify the language that translatable strings are
+written in. By default, \c en is used. See \l QT_I18N_SOURCE_LANGUAGE for
+details.
\section1 Example
-\include cmake-deploy-runtime-dependencies.qdocinc
+\include cmake-generate-deploy-app-script.qdocinc
+
+\sa {Automatic Determination of .ts File Paths}{qt_add_translations()}
*/
diff --git a/src/corelib/doc/src/cmake/qt_wrap_cpp.qdoc b/src/corelib/doc/src/cmake/qt_wrap_cpp.qdoc
index c2a916c71c..3b298a9d7e 100644
--- a/src/corelib/doc/src/cmake/qt_wrap_cpp.qdoc
+++ b/src/corelib/doc/src/cmake/qt_wrap_cpp.qdoc
@@ -6,7 +6,7 @@
\ingroup cmake-commands-qtcore
\title qt_wrap_cpp
-\target qt6_wrap_cpp
+\keyword qt6_wrap_cpp
\summary {Creates .moc files from sources.}
@@ -40,9 +40,23 @@ You can set an explicit \c{TARGET}. This will make sure that the target
properties \c{INCLUDE_DIRECTORIES} and \c{COMPILE_DEFINITIONS} are also used
when scanning the source files with \c{moc}.
+Since Qt 6.8, when a source file is passed to \c{qt_wrap_cpp} instead of a
+header file to generate a \c{.moc} file for a target, the \c{TARGET} parameter
+is needed to set the correct include path for the generated \c{.moc} file in
+the source file. As generated \c{.moc} files are added to the target's
+sources by \c{qt_wrap_cpp}, they are not added to \c{<VAR>}.
+
You can set additional \c{OPTIONS} that should be added to the \c{moc} calls.
You can find possible options in the \l{moc}{moc documentation}.
+The \c{OPTIONS} can evaluate generator expressions when \c{TARGET} is set.
+\note If the \c{OPTIONS} include both generator expressions and special
+characters, use variables to implement them. For example, use \c{$<ANGLE-R>},
+\c{$<COMMA>} and \c{$<SEMICOLON>} instead of \c{>}, \c{,} and \c{:}. Otherwise,
+the generator expression will not be evaluated correctly. \c {OPTIONS} are
+wrapped in generator expressions, so you must escape special characters in
+them.
+
\c{DEPENDS} allows you to add additional dependencies for recreation of the
generated files. This is useful when the sources have implicit dependencies,
like code for a Qt plugin that includes a \c{.json} file using the
@@ -50,5 +64,27 @@ Q_PLUGIN_METADATA() macro.
\section1 Examples
-\snippet cmake-macros/examples.cmake qt_wrap_cpp
+\snippet cmake-macros/examples.cmake qt_wrap_cpp_1
+
+In the following example, the generator expressions passed to \c{OPTIONS}
+will be evaluated since \c{TARGET} is set. The argument is specified this way to
+avoid syntax errors in the generator expressions.
+
+\snippet cmake-macros/examples.cmake qt_wrap_cpp_2
+
+The following example uses \l{https://cmake.org/cmake/help/latest/command/target_compile_definitions.html}{target_compile_definitions}
+to set \l{https://cmake.org/cmake/help/latest/prop_tgt/COMPILE_DEFINITIONS.html}{COMPILE_DEFINITIONS} which will be added to
+\c{OPTIONS}.
+
+\snippet cmake-macros/examples.cmake qt_wrap_cpp_4
+
+\snippet cmake-macros/examples.cpp qt_wrap_cpp_4
+
+In the above file, \c{myapp.moc} is included in \c{myapp.cpp}.
+To generate the \c{myapp.moc} file, the \c{qt_wrap_cpp} macro is used with the
+\c{TARGET} parameter. The first parameter is empty because the \c{.moc} file
+and its path will be added to the target's sources and include directories by
+the \c{qt_wrap_cpp} macro.
+
+\snippet cmake-macros/examples.cmake qt_wrap_cpp_4
*/
diff --git a/src/corelib/doc/src/containers.qdoc b/src/corelib/doc/src/containers.qdoc
index b5f4029fbe..847be1bff6 100644
--- a/src/corelib/doc/src/containers.qdoc
+++ b/src/corelib/doc/src/containers.qdoc
@@ -39,7 +39,8 @@
\note Since Qt 5.14, range constructors are available for most of the
container classes. QMultiMap is a notable exception. Their use is
- encouraged in place of the various from/to methods. For example:
+ encouraged to replace of the various deprecated from/to methods of Qt 5.
+ For example:
\snippet code/doc_src_containers.cpp 25
@@ -285,12 +286,10 @@
In the code snippets so far, we used the unary \c * operator to
retrieve the item (of type QString) stored at a certain iterator
- position, and we then called QString::toLower() on it. Most C++
- compilers also allow us to write \c{i->toLower()}, but some
- don't.
+ position, and we then called QString::toLower() on it.
- For read-only access, you can use const_iterator, \l{QList::constBegin}{constBegin()},
- and \l{QList::constEnd()}{constEnd()}. For example:
+ For read-only access, you can use const_iterator, \l{QList::cbegin}{cbegin()},
+ and \l{QList::cend()}{cend()}. For example:
\snippet code/doc_src_containers.cpp 12
@@ -352,9 +351,10 @@
the problem exists for all the implicitly shared Qt containers.
\section3 Java-Style Iterators
- \l{java-style-iterators}{Java-Style iterators} were introduced in Qt 4. Their API is modelled
+ \l{java-style-iterators}{Java-Style iterators}
+ are modelled
on Java's iterator classes.
- New code should should prefer \l{STL-Style Iterators}.
+ New code should prefer \l{STL-Style Iterators}.
\section1 Qt containers compared with std containers
@@ -384,20 +384,20 @@
\li Similar to std::queue<T>, inherits from \l{QList}.
\row \li \l{QSet}<T>
- \li Similar to std::set<T>. Internally, \l{QSet} is implemented with a
+ \li Similar to std::unordered_set<T>. Internally, \l{QSet} is implemented with a
\l{QHash}.
\row \li \l{QMap}<Key, T>
- \li Similar to std::map<T>.
+ \li Similar to std::map<Key, T>.
\row \li \l{QMultiMap}<Key, T>
- \li Similar to std::multimap<T>.
+ \li Similar to std::multimap<Key, T>.
\row \li \l{QHash}<Key, T>
- \li Most similar to std::map<T>.
+ \li Most similar to std::unordered_map<Key, T>.
\row \li \l{QMultiHash}<Key, T>
- \li Most similar to std::multimap<T>.
+ \li Most similar to std::unordered_multimap<Key, T>.
\endtable
diff --git a/src/corelib/doc/src/custom-types.qdoc b/src/corelib/doc/src/custom-types.qdoc
index 352a43549d..7922fd9477 100644
--- a/src/corelib/doc/src/custom-types.qdoc
+++ b/src/corelib/doc/src/custom-types.qdoc
@@ -6,7 +6,7 @@
\title Creating Custom Qt Types
\brief How to create and register new types with Qt.
- \ingroup best-practices
+ \ingroup how-to
\tableofcontents
@@ -37,7 +37,7 @@
The following \c Message class definition includes these members:
- \snippet tools/customtype/message.h custom type definition
+ \snippet customtype/customtypeexample.cpp custom type definition
The class also provides a constructor for normal use and two public member functions
that are used to obtain the private data.
@@ -53,11 +53,14 @@
to this class, we invoke the Q_DECLARE_METATYPE() macro on the class in the header
file where it is defined:
- \snippet tools/customtype/message.h custom type meta-type declaration
+ \snippet customtype/customtypeexample.cpp custom type meta-type declaration
This now makes it possible for \c Message values to be stored in QVariant objects
- and retrieved later. See the \l{Custom Type Example} for code that demonstrates
- this.
+ and retrieved later:
+
+ \snippet customtype/customtypeexample.cpp storing a custom value
+ \dots
+ \snippet customtype/customtypeexample.cpp retrieving a custom value
The Q_DECLARE_METATYPE() macro also makes it possible for these values to be used as
arguments to signals, but \e{only in direct signal-slot connections}.
@@ -77,7 +80,7 @@
available for queued signal-slot communication as long as you call it before you
make the first connection that uses the type.
- The \l{Queued Custom Type Example} declares a \c Block class which is registered
+ The \l{Queued Custom Type} example declares a \c Block class which is registered
in the \c{main.cpp} file:
\snippet threads/queuedcustomtype/main.cpp main start
@@ -107,18 +110,17 @@
It is often quite useful to make a custom type printable for debugging purposes,
as in the following code:
- \snippet tools/customtype/main.cpp printing a custom type
+ \snippet customtype/customtypeexample.cpp printing a custom type
This is achieved by creating a streaming operator for the type, which is often
defined in the header file for that type:
- \snippet tools/customtype/message.h custom type streaming operator
+ \snippet customtype/customtypeexample.cpp custom type streaming operator declaration
- The implementation for the \c Message type in the \l{Custom Type Example}
- goes to some effort to make the printable representation as readable as
- possible:
+ The implementation for the \c Message type here goes to some effort to make the
+ printable representation as readable as possible:
- \snippet tools/customtype/message.cpp custom type streaming operator
+ \snippet customtype/customtypeexample.cpp custom type streaming operator
The output sent to the debug stream can, of course, be made as simple or as
complicated as you like. Note that the value returned by this function is
@@ -131,9 +133,8 @@
The Q_DECLARE_METATYPE() macro and qRegisterMetaType() function documentation
contain more detailed information about their uses and limitations.
- The \l{Custom Type Example}{Custom Type} and \l{Queued Custom Type Example}
- {Queued Custom Type} examples show how to implement a custom type with the
- features outlined in this document.
+ The \l{Queued Custom Type} example shows how to implement a custom type with
+ the features outlined in this document.
The \l{Debugging Techniques} document provides an overview of the debugging
mechanisms discussed above.
diff --git a/src/corelib/doc/src/datastreamformat.qdoc b/src/corelib/doc/src/datastreamformat.qdoc
index b1b2e6ba34..65b7eb5a20 100644
--- a/src/corelib/doc/src/datastreamformat.qdoc
+++ b/src/corelib/doc/src/datastreamformat.qdoc
@@ -31,7 +31,11 @@
\li QBitArray
\li QBrush
\li QByteArray
+ \li QCborArray
+ \li QCborMap
+ \li QCborValue
\li QColor
+ \li QColorSpace
\li QCursor
\li QDate
\li QDateTime
@@ -39,32 +43,71 @@
\li QFont
\li QGenericMatrix
\li QHash<Key, T>
+ \li QHostAddress
\li QIcon
\li QImage
+ \li QJsonArray
+ \li QJsonDocument
+ \li QJsonObject
+ \li QJsonValue
\li QKeySequence
+ \li QLine
+ \li QLineF
\li QList<T>
+ \li QListWidgetItem
+ \li QLocale
\li QMap<Key, T>
\li QMargins
+ \li QMarginsF
\li QMatrix4x4
- \li QPair<T1, T2>
+ \li QModelIndex
+ \li QModelIndexList
+ \li QMultiHash<Key
+ \li QMultiMap<Key
+ \li QNetworkCacheMetaData
+ \li QNetworkCacheMetaData::AttributesMap
+ \li QPageRanges
+ \li QPainterPath
+ \li std::pair<T1, T2>
\li QPalette
\li QPen
\li QPicture
\li QPixmap
\li QPoint
+ \li QPointF
+ \li QPolygon
+ \li QPolygonF
\li QQuaternion
\li QRect
+ \li QRectF
\li QRegularExpression
\li QRegion
+ \li QSet
\li QSize
+ \li QSizeF
+ \li QSizePolicy
+ \li QStandardItem
\li QString
+ \li QTableWidgetItem
+ \li QTextBlockFormat
+ \li QTextCharFormat
+ \li QTextFormat
+ \li QTextFrameFormat
+ \li QTextLength
+ \li QTextListFormat
+ \li QTextTableCellFormat
+ \li QTimeZone
\li QTime
\li QTransform
+ \li QTreeWidgetItem
+ \li QTypeRevision
\li QUrl
+ \li QUuid
\li QVariant
\li QVector2D
\li QVector3D
\li QVector4D
+ \li QVersionNumber
\endlist
\sa {JSON Support in Qt}, {CBOR Support in Qt}
diff --git a/src/corelib/doc/src/external-resources.qdoc b/src/corelib/doc/src/external-resources.qdoc
index ecda025820..b787651aba 100644
--- a/src/corelib/doc/src/external-resources.qdoc
+++ b/src/corelib/doc/src/external-resources.qdoc
@@ -83,6 +83,36 @@
*/
/*!
+ \externalpage https://developer.android.com/training/data-storage/shared/documents-files
+ \title Android: Access documents and other files from shared storage
+*/
+
+/*!
+ \externalpage https://developer.android.com/reference/androidx/documentfile/provider/DocumentFile#getParentFile()
+ \title Android: DocumentFile.getParentFile()
+*/
+
+/*!
+ \externalpage https://developer.android.com/guide/topics/providers/content-provider-basics#ContentURIs
+ \title Android: Content URIs
+*/
+
+/*!
+ \externalpage https://developer.android.com/training/data-storage#scoped-storage
+ \title Android: Scoped storage
+*/
+
+/*!
+ \externalpage https://developer.android.com/training/data-storage/use-cases
+ \title Android: storage best practices
+*/
+
+/*!
+ \externalpage https://developer.android.com/reference/android/provider/MediaStore
+ \title Android: MediaStore
+*/
+
+/*!
\externalpage https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
\title GNUInstallDirs
*/
@@ -131,3 +161,13 @@
\externalpage https://cmake.org/cmake/help/latest/prop_tgt/FOLDER.html
\title FOLDER
*/
+
+/*!
+ \externalpage https://cmake.org/cmake/help/latest/command/cmake_policy.html
+ \title cmake_policy
+*/
+
+/*!
+ \externalpage https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#creating-packages
+ \title Creating CMake packages
+*/
diff --git a/src/corelib/doc/src/foreach-keyword.qdoc b/src/corelib/doc/src/foreach-keyword.qdoc
index 780be6e09c..6aa21d5880 100644
--- a/src/corelib/doc/src/foreach-keyword.qdoc
+++ b/src/corelib/doc/src/foreach-keyword.qdoc
@@ -31,7 +31,7 @@
\snippet code/doc_src_containers.cpp 16
- Unless the data type contains a comma (e.g., \c{QPair<int,
+ Unless the data type contains a comma (e.g., \c{std::pair<int,
int>}), the variable used for iteration can be defined within the
\c foreach statement:
@@ -73,4 +73,18 @@
\c foreach would not. But using \c foreach always copies the container,
which is usually not cheap for STL containers. If in doubt, prefer
\c foreach for Qt containers, and range based \c for for STL ones.
+
+ You can remove the availability of the Qt's \c foreach loop by
+ defining the \c{QT_NO_FOREACH} macro.
+*/
+
+/*!
+ \macro QT_NO_FOREACH
+ \since 6.0
+ \relates <QtGlobal>
+
+ Defining this macro removes the availability of Qt's \c foreach
+ loop.
+
+ \sa QT_NO_KEYWORDS
*/
diff --git a/src/corelib/doc/src/includes/android-content-uri-limitations.qdocinc b/src/corelib/doc/src/includes/android-content-uri-limitations.qdocinc
new file mode 100644
index 0000000000..0521aff662
--- /dev/null
+++ b/src/corelib/doc/src/includes/android-content-uri-limitations.qdocinc
@@ -0,0 +1,13 @@
+On Android, some limitations apply when dealing with
+\l {Android: Content URIs}{content URIs}:
+\list
+ \li Access permissions might be needed by prompting the user through the
+ \l QFileDialog which implements
+ \l {Android: Access documents and other files from shared storage}{Android's native file picker}.
+ \li Aim to follow the \l {Android: Scoped storage}{Scoped storage} guidelines,
+ such as using app specific directories instead of other public external directories.
+ For more information, also see
+ \l {Android: storage best practices}{storage best practices}.
+ \li Due to the design of Qt APIs (e.g. QFile), it's not possible to fully
+ integrate the latter APIs with Android's \l {Android: MediaStore}{MediaStore} APIs.
+\endlist
diff --git a/src/corelib/doc/src/includes/cmake-android-qt-finalize-project-warning.qdocinc b/src/corelib/doc/src/includes/cmake-android-qt-finalize-project-warning.qdocinc
index 3f2a4ab6ec..47133f6d10 100644
--- a/src/corelib/doc/src/includes/cmake-android-qt-finalize-project-warning.qdocinc
+++ b/src/corelib/doc/src/includes/cmake-android-qt-finalize-project-warning.qdocinc
@@ -1,6 +1,8 @@
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+//! [warning]
\warning If your \e Android project is built using a CMake version lower than
3.19, make sure that you call \l{qt_finalize_project}{qt6_finalize_project()} at
the end of a top-level CMakeLists.txt.
+//! [warning]
diff --git a/src/corelib/doc/src/includes/cmake-deploy-modified-variable-values.qdocinc b/src/corelib/doc/src/includes/cmake-deploy-modified-variable-values.qdocinc
index 6c1f20adb2..632ddf756f 100644
--- a/src/corelib/doc/src/includes/cmake-deploy-modified-variable-values.qdocinc
+++ b/src/corelib/doc/src/includes/cmake-deploy-modified-variable-values.qdocinc
@@ -2,8 +2,11 @@
cmake_minimum_required(VERSION 3.16...3.22)
project(MyThings)
+# The following CMAKE_INSTALL_*DIR variables are used to initialize their
+# QT_DEPLOY_*_DIR counterparts.
set(CMAKE_INSTALL_BINDIR "mybindir")
set(CMAKE_INSTALL_LIBDIR "mylibdir")
+set(CMAKE_INSTALL_LIBEXECDIR "mylibexecdir")
find_package(Qt6 REQUIRED COMPONENTS Core)
qt_standard_project_setup()
@@ -15,10 +18,13 @@ file(GENERATE OUTPUT ${deploy_script} CONTENT "
set(QT_DEPLOY_PLUGINS_DIR \"mypluginsdir\")
set(QT_DEPLOY_QML_DIR \"myqmldir\")
+set(QT_DEPLOY_TRANSLATIONS_DIR \"i18n\")
include(\"${QT_DEPLOY_SUPPORT}\")
qt_deploy_runtime_dependencies(
EXECUTABLE \"\${QT_DEPLOY_BIN_DIR}/$<TARGET_FILE_NAME:MyApp>\"
)")
+
+install(SCRIPT ${deploy_script})
\endcode
diff --git a/src/corelib/doc/src/includes/cmake-deploy-runtime-dependencies-deploy-tool-options.qdocinc b/src/corelib/doc/src/includes/cmake-deploy-runtime-dependencies-deploy-tool-options.qdocinc
new file mode 100644
index 0000000000..0f46379c45
--- /dev/null
+++ b/src/corelib/doc/src/includes/cmake-deploy-runtime-dependencies-deploy-tool-options.qdocinc
@@ -0,0 +1,20 @@
+\badcode
+set(deploy_tool_options_arg "")
+if(APPLE)
+ set(deploy_tool_options_arg --hardened-runtime)
+elseif(WIN32)
+ set(deploy_tool_options_arg --no-compiler-runtime)
+endif()
+
+# Generate a deployment script to be executed at install time
+qt_generate_deploy_script(
+ TARGET MyApp
+ OUTPUT_SCRIPT deploy_script
+ CONTENT "
+qt_deploy_runtime_dependencies(
+ EXECUTABLE \"${executable_path}\"
+ DEPLOY_TOOL_OPTIONS "${deploy_tool_options_arg}"
+ GENERATE_QT_CONF
+ VERBOSE
+)")
+\endcode
diff --git a/src/corelib/doc/src/includes/cmake-deploy-runtime-dependencies.qdocinc b/src/corelib/doc/src/includes/cmake-deploy-runtime-dependencies.qdocinc
index 26503ddece..6d026d6301 100644
--- a/src/corelib/doc/src/includes/cmake-deploy-runtime-dependencies.qdocinc
+++ b/src/corelib/doc/src/includes/cmake-deploy-runtime-dependencies.qdocinc
@@ -26,7 +26,7 @@ set(helper_app_path "\${QT_DEPLOY_BIN_DIR}/$<TARGET_FILE_NAME:HelperApp>")
# Generate a deployment script to be executed at install time
qt_generate_deploy_script(
TARGET MyApp
- FILENAME_VARIABLE deploy_script
+ OUTPUT_SCRIPT deploy_script
CONTENT "
qt_deploy_runtime_dependencies(
EXECUTABLE \"${executable_path}\"
diff --git a/src/corelib/doc/src/includes/cmake-deploy-var-usage.qdocinc b/src/corelib/doc/src/includes/cmake-deploy-var-usage.qdocinc
index c5a1a40356..27e04b5b08 100644
--- a/src/corelib/doc/src/includes/cmake-deploy-var-usage.qdocinc
+++ b/src/corelib/doc/src/includes/cmake-deploy-var-usage.qdocinc
@@ -1,2 +1,6 @@
This variable is defined by the script named by \l QT_DEPLOY_SUPPORT. It should
only be used as part of deployment during installation or a post-build rule.
+
+\note This is a low-level deployment API variable, and should only be used in
+advanced use-cases that are not covered by the higher-level API commands, like
+\l{qt_generate_deploy_app_script}.
diff --git a/src/corelib/doc/src/includes/cmake-generate-deploy-app-script-deploy-tool-options.qdocinc b/src/corelib/doc/src/includes/cmake-generate-deploy-app-script-deploy-tool-options.qdocinc
new file mode 100644
index 0000000000..64c6b3e49f
--- /dev/null
+++ b/src/corelib/doc/src/includes/cmake-generate-deploy-app-script-deploy-tool-options.qdocinc
@@ -0,0 +1,16 @@
+\badcode
+set(deploy_tool_options_arg "")
+if(APPLE)
+ set(deploy_tool_options_arg --hardened-runtime)
+elseif(WIN32)
+ set(deploy_tool_options_arg --no-compiler-runtime)
+endif()
+
+qt_generate_deploy_app_script(
+ TARGET MyApp
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+ DEPLOY_TOOL_OPTIONS ${deploy_tool_options_arg}
+)
+install(SCRIPT ${deploy_script})
+\endcode
diff --git a/src/corelib/doc/src/includes/cmake-generate-deploy-app-script.qdocinc b/src/corelib/doc/src/includes/cmake-generate-deploy-app-script.qdocinc
new file mode 100644
index 0000000000..d5c1d2cf4a
--- /dev/null
+++ b/src/corelib/doc/src/includes/cmake-generate-deploy-app-script.qdocinc
@@ -0,0 +1,21 @@
+\badcode
+cmake_minimum_required(VERSION 3.16...3.22)
+project(MyThings)
+
+find_package(Qt6 REQUIRED COMPONENTS Core)
+qt_standard_project_setup()
+
+qt_add_executable(MyApp main.cpp)
+
+install(TARGETS MyApp
+ BUNDLE DESTINATION .
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+)
+
+qt_generate_deploy_app_script(
+ TARGET MyApp
+ OUTPUT_SCRIPT deploy_script
+ NO_UNSUPPORTED_PLATFORM_ERROR
+)
+install(SCRIPT ${deploy_script})
+\endcode
diff --git a/src/corelib/doc/src/includes/models.qdocinc b/src/corelib/doc/src/includes/models.qdocinc
new file mode 100644
index 0000000000..cf840b1cae
--- /dev/null
+++ b/src/corelib/doc/src/includes/models.qdocinc
@@ -0,0 +1,14 @@
+//! [thread-safety-section1]
+\section1 Thread safety
+
+Being a \l {Accessing QObject Subclasses from Other Threads}{subclass of
+QObject}, \1 is not \l {Reentrancy and Thread-Safety}{thread-safe}. Any \1
+model-related API should only be called from the thread the model object lives
+in. If the \1 is connected with a view, that means the GUI thread, as that is
+where the view lives, and it will call into the model from the GUI thread.
+Using a background thread to populate or modify the contents of a model is
+possible, but requires care, as the background thread cannot call any
+model-related API directly. Instead, you should queue the updates and apply
+them in the main thread. This can be done with \l {Signals and Slots Across
+Threads}{queued connections}.
+//! [thread-safety-section1]
diff --git a/src/corelib/doc/src/includes/qstring.qdocinc b/src/corelib/doc/src/includes/qstring.qdocinc
new file mode 100644
index 0000000000..66ed12dff3
--- /dev/null
+++ b/src/corelib/doc/src/includes/qstring.qdocinc
@@ -0,0 +1,36 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+// \1 is either "search" or "comparison"
+//! [search-comparison-case-sensitivity]
+If \a cs is Qt::CaseSensitive (the default), the \1 is case-sensitive;
+otherwise the \1 is case-insensitive.
+//! [search-comparison-case-sensitivity]
+
+//! [negative-index-start-search-from-end]
+If \a from is -1, the search starts at the last character; if it is
+-2, at the next to last character and so on.
+//! [negative-index-start-search-from-end]
+
+//! [qstring-first-index-of]
+Returns the index position of the first occurrence of the \1 \a \2
+in this string, searching forward from index position \a from.
+Returns -1 if \a \2 is not found.
+//! [qstring-first-index-of]
+
+//! [qstring-last-index-of]
+Returns the index position of the last occurrence of the \1 \a \2
+in this string, searching backward from index position \a from.
+//! [qstring-last-index-of]
+
+//! [qstring-local-8-bit-equivalent]
+On Unix systems this is equivalent to \1().
+Note that on Apple systems this function does not take
+\l{https://developer.apple.com/documentation/foundation/nsstring/1410091-defaultcstringencoding?language=objc}
+{NSString.defaultCStringEncoding} or
+\l{https://developer.apple.com/documentation/corefoundation/1541720-cfstringgetsystemencoding?language=objc}
+{CFStringGetSystemEncoding()} into account, as these functions
+typically return the legacy "Western (Mac OS Roman)" encoding,
+which should not be used on modern Apple operating systems.
+On Windows the system's current code page is used.
+//! [qstring-local-8-bit-equivalent]
diff --git a/src/corelib/doc/src/io.qdoc b/src/corelib/doc/src/io.qdoc
index 80caf9a769..443d324f75 100644
--- a/src/corelib/doc/src/io.qdoc
+++ b/src/corelib/doc/src/io.qdoc
@@ -10,7 +10,7 @@
network handling.
These \l{Qt Core} classes are used to handle input and output to and from
- external devices, processes, files etc. as well as manipulating files and
+ external devices, processes, files etc., as well as manipulating files and
directories.
*/
diff --git a/src/corelib/doc/src/ipc.qdoc b/src/corelib/doc/src/ipc.qdoc
new file mode 100644
index 0000000000..7ec6f5fa3b
--- /dev/null
+++ b/src/corelib/doc/src/ipc.qdoc
@@ -0,0 +1,492 @@
+// Copyright (C) 2022 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \page ipc.html
+ \title Inter-Process Communication
+ \ingroup groups
+ \ingroup frameworks-technologies
+ \keyword ipc
+ \ingroup explanations-networkingandconnectivity
+
+ \brief An overview of Qt's inter-process communication functionality
+
+ Qt supports many ways of communicating with other processes running in the
+ same system or in different systems. There are basically three types of
+ inter-process communication mechanisms:
+
+ \list 1
+ \li Synchronization primitives
+ \li Exchanging of arbitrary byte-level data
+ \li Passing structured messages
+ \endlist
+
+ \section1 Synchronization primitives
+
+ Qt only provides one class for explicit inter-process synchronization:
+ \l{QSystemSemaphore}. A QSystemSemaphore is like a \l{QSemaphore} that is
+ accessible by multiple processes in the same system. It is globally
+ identified by a "key", which in Qt is represented by the \l{QNativeIpcKey}
+ class. Additionally, depending on the OS, Qt may support multiple different
+ backends for sharing memory; see the \l{Native IPC Keys} documentation for
+ more information and limitations.
+
+ It is possible to use regular thread-synchronization primitives such as
+ mutexes, wait conditions, and read-write locks, located in memory that is
+ shared between processes. Qt does not provide any class to support this,
+ but applications can use low-level operations on certain operating systems.
+
+ Other Qt classes may be used to provide higher-level locking, like
+ \l{QLockFile}, or by acquiring a unique, system-wide resource. Such
+ techniques include \l{QTcpServer}{TCP} or \l{QUdpSocket}{UDP} ports or
+ well-known names in \l{QDBusConnection::registerService}{D-Bus}.
+
+ \section1 Byte-level data sharing
+
+ Using byte-level data, applications can implement any communication
+ protocol they may choose. Sharing of byte data can be stream-oriented
+ (serialized) or can allow random access (a similar condition to
+ QFileDevice::isSequential()).
+
+ For serial communication, Qt provides a number of different classes and
+ even full modules:
+ \list
+ \li Pipes and FIFOs: \l QFile
+ \li Child processes: \l QProcess
+ \li Sockets: \l QTcpSocket, \l QUdpSocket (in \l{Qt Network})
+ \li HTTP(S): \l QNetworkAccessManager (in \l{Qt Network}) and
+ \l QHttpServer (in \l{Qt HTTP Server})
+ \li CoAP(S): \l QCoapClient (in \l{Qt CoAP})
+ \endlist
+
+ For random-access data sharing within the same system, Qt provides
+ \l{QSharedMemory}. See the \l{Shared Memory} documentation for detailed
+ information.
+
+ \section1 Structured message passing
+
+ Qt also provides a number of techniques to exchange structured messages
+ with other processes. Applications can build on top of the byte-level
+ solutions above, such as by using \l QJsonDocument or \l QXmlStreamReader /
+ \l QXmlStreamWriter over HTTP to perform JSONRPC or XMLRPC, respectively,
+ or \l QCborValue with QtCoAP.
+
+ Dedicated Qt modules for structured messages and remote procedure-calling
+ include:
+ \list
+ \li \l{Qt D-Bus}
+ \li \l{Qt Remote Objects}
+ \li \l{Qt WebSockets}
+ \endlist
+*/
+
+/*!
+ \page shared-memory.html
+ \title Shared Memory
+ \keyword ipc
+ \keyword shared memory
+
+ \brief Overview of the techniques for sharing memory between processes.
+
+ Qt provides two techniques to share memory with other processes in the same
+ system: \l{QSharedMemory} and memory-mapped files using \l{QFile}. Memory
+ that is shared with other processes is often referred to as a "segment",
+ and although it may have been implemented as specific segments on
+ processors with segmented memory models in the past, this is not the case
+ in any modern operating system. Shared memory segments are simply regions
+ of memory that the operating system will ensure are available to all
+ processes participating.
+
+ \note The address at which the segment is located in memory will almost
+ always be different for each process that is participating in the sharing.
+ Therefore, applications must take care to share only position-independent
+ data, such as primitive C++ types or arrays of such types.
+
+ \section1 Sharing memory using QSharedMemory
+
+ QSharedMemory provides a simple API to create a shared memory segment of a
+ given size or attach to one that was created by another process.
+ Additionally, it provides a pair of methods to \l{QSharedMemory::}{lock}
+ and \l{QSharedMemory::}{unlock} the whole segment, using an internal
+ \l{QSystemSemaphore}.
+
+ Shared memory segments and system semaphores are globally identified in the
+ system through a "key", which in Qt is represented by the \l{QNativeIpcKey}
+ class. Additionally, depending on the OS, Qt may support multiple different
+ backends for sharing memory; see the \l{Native IPC Keys} documentation for
+ more information and limitations.
+
+ QSharedMemory is designed to share memory only within the same privilege
+ level (that is, not with untrusted other processes, such as those started
+ by other users). For backends that support it, QSharedMemory will create
+ segments such that only processes with the same privilege level can attach.
+
+ \section1 Sharing memory via memory-mapped files
+
+ Most files can be mapped to memory using QFile::map() and, if the
+ \l{QFileDevice::MapPrivateOption}{MapPrivateOption} option is not specified,
+ any writes to the mapped segment will be observed by all other processes
+ that have mapped the same file. Exceptions to files that can be mapped to
+ memory include remote files found in network shares or those located in
+ certain filesystems. Even if the operating system does allow mapping remote
+ files to memory, I/O operations on the file will likely be cached and
+ delayed, thus making true memory sharing impossible.
+
+ This solution has the major advantages of being independent of any backend
+ API and of being simpler to interoperate with from non-Qt applications.
+ Since \l{QTemporaryFile} is a \l{QFile}, applications can use that class to
+ achieve clean-up semantics and to create unique shared memory segments too.
+
+ To achieve locking of the shared memory segment, applications will need to
+ deploy their own mechanisms. One way may be to use \l QLockFile. Another
+ and less costly solution is to use QBasicAtomicInteger or \c{std::atomic} in
+ a pre-determined offset in the segment itself. Higher-level locking
+ primitives may be available on some operating systems; for example, on
+ Linux, applications can set the "pshared" flag in the mutex attribute
+ passed to \c{pthread_mutex_create()} to indicate that the mutex resides in
+ a shared memory segment.
+
+ Be aware that the operating system will likely attempt to commit to
+ permanent storage any writes made to the shared memory. This may be desired
+ or it may be a performance penalty if the file itself was meant to be
+ temporary. In that case, applications should locate a RAM-backed
+ filesystem, such as \c{tmpfs} on Linux (see
+ QStorageInfo::fileSystemType()), or pass a flag to the native file-opening
+ function to inform the OS to avoid committing the contents to storage.
+
+ It is possible to use file-backed shared memory to communicate with
+ untrusted processes, in which case the application should exercise great
+ care. The files may be truncated/shrunk and cause applications accessing
+ memory beyond the file's size to crash.
+
+ \section2 Linux hints on memory-mapped files
+
+ On modern Linux systems, while the \c{/tmp} directory is often a \c{tmpfs}
+ mount point, that is not a requirement. However, the \c{/dev/shm} directory
+ is required to be a \c{tmpfs} and exists for the very purpose of sharing
+ memory. Do note that it is world-readable and writable (like \c{/tmp} and
+ \c{/var/tmp}), so applications must be careful of the contents revealed
+ there. Another alternative is to use the XDG Runtime Directory (see
+ QStandardPaths::writableLocation() and \l{QStandardPaths::RuntimeLocation}),
+ which on Linux systems using systemd is a user-specific \c{tmpfs}.
+
+ An even more secure solution is to create a "memfd" using \c{memfd_create(2)}
+ and use interprocess communication to pass the file descriptor, like
+ \l{QDBusUnixFileDescriptor} or by letting the child process of a \l{QProcess}
+ inherit it. "memfds" can also be sealed against being shrunk, so they are
+ safe to be used when communicating with processes with a different privilege
+ level.
+
+ \section2 FreeBSD hints on memory-mapped files
+
+ FreeBSD also has \c{memfd_create(2)} and can pass file descriptors to other
+ processes using the same techniques as Linux. It does not have temporary
+ filesystems mounted by default.
+
+ \section2 Windows hints on memory-mapped files
+
+ On Windows, the application can request the operating system avoid saving
+ the file's contents on permanent storage. This request is performed by
+ passing the \c{FILE_ATTRIBUTE_TEMPORARY} flag in the
+ \c{dwFlagsAndAttributes} parameter to the \c{CreateFile} Win32 function,
+ the \c{_O_SHORT_LIVED} flag to \c{_open()} low-level function, or by
+ including the modifier "T" to the
+ \c{fopen()} C runtime function.
+
+ There's also a flag to inform the operating system to delete the file when
+ the last handle to it is closed (\c{FILE_FLAG_DELETE_ON_CLOSE},
+ \c{_O_TEMPORARY}, and the "D" modifier), but do note that all processes
+ attempting to open the file must agree on using this flag or not using it. A
+ mismatch will likely cause a sharing violation and failure to open the file.
+*/
+
+/*!
+ \page native-ipc-keys.html
+ \title Native IPC Keys
+ \keyword ipc
+ \keyword shared memory
+ \keyword system semaphore
+
+ \brief An overview of keys for QSharedMemory and QSystemSemaphore
+
+ The \l QSharedMemory and \l QSystemSemaphore classes identify their
+ resource using a system-wide identifier known as a "key". The low-level key
+ value as well as the key type are encapsulated in Qt using the \l
+ QNativeIpcKey class. That class also provides the proper means of
+ exchanging the key with other processes, by way of
+ QNativeIpcKey::toString() and QNativeIpcKey::fromString().
+
+ Qt currently supports three distinct backends for those two classes, which
+ match the values available in the \l{QNativeIpcKey::Type} enumeration.
+ \list
+ \li POSIX Realtime extensions (IEEE 1003.1b, POSIX.1b)
+ \li X/Open System Interfaces (XSI) or System V (SVr4), though also now part of POSIX
+ \li Windows primitives
+ \endlist
+
+ As the name indicates, the Windows primitives are only available on the
+ Windows operating system, where they are the default backend. The other two
+ are usually both available on Unix operating systems. The following table
+ provides an overview of typical availability since Qt 6.6:
+
+ \table
+ \header \li Operating system \li POSIX \li System V \li Windows
+ \row \li Android \li \li \li
+ \row \li INTEGRITY \li \li \li
+ \row \li QNX \li Yes \li \li
+ \row \li \macos \li Yes \li Usually (1) \li
+ \row \li Other Apple OSes \li Yes \li \li
+ \row \li Other Unix systems \li Yes \li Yes \li
+ \row \li Windows \li Rarely (2) \li \li Yes
+ \endtable
+
+ \note 1 Sandboxed \macos applications, which include all applications
+ distributed via the Apple App Store, may not use System V objects.
+
+ \note 2 Some GCC-compatible C runtimes on Windows provide POSIX-compatible
+ shared memory support, but this is rare. It is always absent with the
+ Microsoft compiler.
+
+ To determine whether a given key type is supported, applications should
+ call QSharedMemory::isKeyTypeSupported() and
+ QSystemSemaphore::isKeyTypeSupported().
+
+ QNativeIpcKey also provides support for compatibility with Qt applications
+ prior to its introduction. The following sections detail the limitations of
+ the backends, the contents of the string keys themselves, and
+ compatibility.
+
+ \section1 Cross-platform safe key format
+
+ QNativeIpcKey::setNativeKey() and QNativeIpcKey::nativeKey() handle the
+ low-level native key, which may be used with the native APIs and shared
+ with other, non-Qt processes (see below for the API). This format is not
+ usually cross-platform, so both QSharedMemory and QSystemSemaphore provide
+ a function to translate a cross-platform identifier string to the native
+ key: QSharedMemory::platformSafeKey() and
+ QSystemSemaphore::platformSafeKey().
+
+ The length of the cross-platform key on most platforms is the same as that
+ of a file name, but is severely limited on Apple platforms to only 30
+ usable bytes (be mindful of UTF-8 encoding if using characters outside the
+ US-ASCII range). The format of the key is also similar to that of a file
+ path component, meaning it should not contain any characters not allowed in
+ file names, in particular those that separate path components (slash and
+ backslash), with the exception of sandboxed applications on Apple operating
+ systems. The following are good examples of cross-platform keys: "myapp",
+ "org.example.myapp", "org.example.myapp-12345". Note that it is up to the
+ caller to prevent oversized keys, and to ensure that the key contains legal
+ characters on the respective platform. Qt will silently truncate keys that
+ are too long.
+
+ \b{Apple sandbox limitations:} if the application is running inside of a
+ sandbox in an Apple operating system, the key must be in a very specific
+ format: \c {<application group identifier>/<custom identifier>}. Sandboxing
+ is implied for all applications distributed through the Apple App Store.
+ See Apple's documentation
+ \l{https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html#//apple_ref/doc/uid/TP40011183-CH3-SW24}
+ {here} and \l{https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_application-groups}
+ {here} for more information, including how to obtain the application's group identifier.
+
+ \section1 Native key format
+
+ This section details the format of the native keys of the supported
+ backends.
+
+ \section3 POSIX Realtime
+ Native keys resemble file names and may contain any character that file
+ names do, except for a slash. POSIX requires the first character in the key
+ name to be a slash and leaves undetermined whether any additional slashes
+ are permitted. On most operating systems, the key length is the same as a
+ file name, but it is limited to 32 characters on Apple operating systems
+ (this includes the first slash and the terminating null, so only 30 usable
+ characters are possible).
+
+ The following are good examples of native POSIX keys: "/myapp",
+ "/org.example.myapp", "/org.example.myapp-12345".
+
+ QSharedMemory::platformSafeKey() and QSystemSemaphore::platformSafeKey()
+ simply prepend the slash. On Apple operating systems, they also truncate
+ the result to the available size.
+
+ \section3 Windows
+ Windows key types are NT
+ \l{https://learn.microsoft.com/en-us/windows/win32/sync/object-namespaces}{kernel
+ object names} and may be up to \c{MAX_PATH} (260) characters in length.
+ They look like relative paths (that is, they don't start with a backslash
+ or a drive letter), but unlike file names on Windows, they are
+ case-sensitive.
+
+ The following are good examples of native Windows keys: "myapp",
+ "org.example.myapp", "org.example.myapp-12345".
+
+ QSharedMemory::platformSafeKey() and QSystemSemaphore::platformSafeKey()
+ insert a prefix to disambiguate shared memory and system semaphores,
+ respectively.
+
+ \section3 X/Open System Interfaces (XSI) / System V
+ System V keys take the form of the name of a file in the system, and thus
+ have the exact same limitations as file paths do. Both QSharedMemory and
+ QSystemSemaphore will create this file if it does not exist when creating
+ the object. If auto-removal is disabled, it may also be shared between
+ QSharedMemory and QSystemSemaphore without conflict and can be any extant
+ file (for example, it can be the process executable itself, see
+ QCoreApplication::applicationFilePath()). The path should be an absolute
+ one to avoid mistakes due to different current directories.
+
+ QSharedMemory::platformSafeKey() and QSystemSemaphore::platformSafeKey()
+ always return an absolute path. If the input was already absolute, they
+ will return their input unchanged. Otherwise, they will prepend a suitable
+ path where the application usually has permission to create files in.
+
+ \section1 Ownership
+
+ Shared memory and system semaphore objects need to be created before use,
+ which is accomplished with QSharedMemory::create() or by passing
+ QSystemSemaphore::Create to the constructor, respectively.
+
+ On Unix systems, the Qt classes that created the object will be responsible
+ for cleaning up the object in question. Therefore, if the application with
+ that C++ object exits uncleanly (a crash, qFatal(), etc.), the object may
+ be left behind. If that happens, applications may fail to create the
+ object again and should instead attach to an existing one. For example, for
+ QSharedMemory:
+
+ \code
+ if (!shm.create(4096) && shm.error() == QSharedMemory::AlreadyExists)
+ shm.attach();
+ \endcode
+
+ Re-attaching to a QSystemSemaphore is probably unwise, as the token counter
+ in it is probably in an unknown state and therefore may lead to deadlocks.
+
+ \section3 POSIX Realtime
+ POSIX Realtime object ownership is patterned after files, in the sense that
+ they exist independent of any process using them or not. Qt is unable to
+ determine if the object is still in use, so auto-removal will remove it
+ even then, which will make attaching to the same object impossible but
+ otherwise not affecting existing attachments.
+
+ Prior to Qt 6.6, Qt never cleaned up POSIX Realtime objects, except on QNX.
+
+ \section3 X/Open System Interfaces (XSI) / System V
+ There are two resources managed by the Qt classes: the file the key refers
+ to and the object itself. QSharedMemory manages the object cooperatively:
+ the last attachment is responsible for removing the object itself and then
+ removing the key file. QSystemSemaphore will remove the object if and only
+ if it was passed QSystemSemaphore::Create; additionally, if it created the
+ key file, it will remove that too.
+
+ Since Qt 6.6, it is possible to ask either class not to clean up.
+
+ \section3 Windows
+ The operating system owns the object and will clean up after the last
+ handle to the object is closed.
+
+ \section1 Interoperability with old Qt applications
+
+ The QNativeIpcKey class was introduced in Qt 6.6. Prior to this version,
+ QSharedMemory and QSystemSemaphore backends were determined at the time of
+ Qt's own build. For Windows systems, it was always the Windows backend. For
+ Unix systems, it defaulted to the System V backend if the configuration
+ script determined it was available. If it was not available, it fell back
+ to the POSIX one. The POSIX backend could be explicitly
+ selected using the \c{-feature-ipc_posix} option to the Qt configure
+ script; if it was enabled, the \c{QT_POSIX_IPC} macro would be defined.
+
+ Qt 6.6 retains the configure script option but it no longer controls the
+ availability of the backends. Instead, it changes what
+ QNativeIpcKey::legacyDefaultTypeForOs() will return. Applications that need
+ to retain compatibility must use this key type exclusively to guarantee
+ interoperability.
+
+ The API in both QSharedMemory and QSystemSemaphore had the concept of a
+ cross-platform key, which is now deprecated in favor of using
+ QSharedMemory::legacyNativeKey() and QSystemSemaphore::legacyNativeKey().
+ Those two functions produce the same native key as the deprecated functions
+ did in prior versions. If the old code was for example:
+
+ \code
+ QSharedMemory shm("org.example.myapplication");
+ QSystemSemaphore sem("org.example.myapplication");
+ \endcode
+
+ It can be updated to be:
+ \code
+ QSharedMemory shm(QSharedMemory::legacyNativeKey("org.example.myapplication"));
+ QSystemSemaphore sem(QSystemSemaphore::legacyNativeKey("org.example.myapplication"));
+ \endcode
+
+ If the two applications exchanged native keys, there is no need to update
+ code such as:
+
+ \code
+ QSharedMemory shm;
+ shm.setNativeKey(key);
+ \endcode
+
+ Though if the older application did accept a native key, the new one may
+ opt to use \c{platformSafeKey()} with a second argument of
+ QNativeIpcKey::legacyDefaultTypeForOs().
+
+ \section3 X/Open System Interfaces (XSI) / System V
+ Never use existing files for QSharedMemory keys, as the old Qt application
+ may attempt to remove it. Instead, let QSharedMemory create it.
+
+ \section1 Interoperability with non-Qt applications
+
+ Interoperability with non-Qt applications is possible, with some limitations:
+ \list
+ \li Creation of shared memory segments must not race
+ \li QSharedMemory support for locking the segment is unavailable
+ \endlist
+
+ Communication with non-Qt applications must always be through the native
+ key.
+
+ QSharedMemory always maps the entire segment to memory. The non-Qt
+ application may choose to only map a subset of it to memory, with no ill
+ effects.
+
+ \section3 POSIX Realtime
+ POSIX shared memory can be opened using
+ \l{https://pubs.opengroup.org/onlinepubs/9699919799/functions/shm_open.html}{shm_open()}
+ and POSIX system semaphores can be opened using
+ \l{https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_open.html}{sem_open()}.
+
+ Both of those functions take a \c name parameter that is the result of
+ QNativeIpcKey::nativeKey(), encoded for file names using
+ QFile::encodeName() / QFile::decodeName().
+
+ \section3 Windows
+ Windows shared memory objects can be opened using
+ \l{https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-createfilemappingw}{CreateFileMappingW}
+ and Windows system semaphore objects can be opened using
+ \l{https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-createsemaphorew}{CreateSemaphoreW}.
+ Despite the name of both functions starting with "Create", they are able
+ to attach to existing objects.
+
+ The \c lpName parameter to those functions is the result of
+ QNativeIpcKey::nativeKey(), without transformation.
+
+ If the foreign application uses the non-Unicode version of those functions
+ (ending in "A"), the name can be converted to and from 8-bit using QString.
+
+ \section3 X/Open System Interfaces (XSI) / System V
+ System V shared memory can be obtained using
+ \l{https://pubs.opengroup.org/onlinepubs/9699919799/functions/shmget.html}{shmget()}
+ and System V system semaphores can be obtained using
+ \l{https://pubs.opengroup.org/onlinepubs/9699919799/functions/semget.html}{semget()}.
+
+ The \c{key} parameter to either of those functions is the result of the
+ \l{https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftok.html}{ftok()}
+ function when passed the file name obtained from QNativeIpcKey::nativeKey()
+ with an \c id of 81 or 0x51 (the ASCII capital letter 'Q').
+
+ System V semaphore objects may contain multiple semaphores, but
+ QSystemSemaphore only uses the first one (number 0 for \c{sem_num}).
+
+ Both QSharedMemory and QSystemSemaphore default to removing the object
+ using the \c{IPC_RMID} operation to \c{shmctl()} and \c{semctl()}
+ respectively if they are the last attachment.
+*/
diff --git a/src/corelib/doc/src/jni.qdoc b/src/corelib/doc/src/jni.qdoc
new file mode 100644
index 0000000000..d05dd44ff6
--- /dev/null
+++ b/src/corelib/doc/src/jni.qdoc
@@ -0,0 +1,230 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \namespace QtJniTypes
+ \inmodule QtCore
+ \ingroup frameworks-technologies
+ \keyword JNI
+ \since 6.8
+
+ \brief The QtJniTypes namespace declares C++ types that correspond to Java types.
+
+ The \l{Java Native Interface Specification}{Java Native Interface}
+ framework enables native C or C++ code to call Java APIs, and to register
+ native C or C++ functions that Java code should be able to call with the
+ JVM. In Qt, the QJniObject and QJniEnvironment types provide convenient
+ wrappers for using JNI.
+
+ Since the Java language, similar to C++, supports overloading, functions
+ need to be specified including their entire signature string. This is
+ complex, repetitive, and error prone, especially when functions take
+ several parameters. QJniObject provides variadic template APIs that can
+ deduce the signature string for a function call at compile time, based on
+ the C++ types passed into the template. For this to work, the mapping of
+ those C++ types to their corresponding JNI string needs to be known at
+ compile time.
+
+ Qt implements this mapping for the standard \l {JNI types}.
+ By using the Q_DECLARE_JNI_CLASS macro, the mapping can be extended for
+ arbitrary Java types.
+
+ \sa Q_DECLARE_JNI_CLASS, Q_DECLARE_JNI_NATIVE_METHOD, Q_JNI_NATIVE_METHOD
+*/
+
+/*!
+ \macro Q_DECLARE_JNI_TYPE(Type, JavaSignature)
+ \internal
+ \relates QtJniTypes
+ \since 6.8
+
+ Declares a C++ type \a Type in the QtJniTypes namespace that wraps the Java
+ type \a JavaSignature. The signature needs to start with \c{[L} to indicate
+ an array of a class, or with \c{L} for classes, and end with a semicolon
+ \c{;}.
+
+ \code
+ Q_DECLARE_JNI_TYPE(StringArray, "[Ljava/lang/String;")
+ \endcode
+
+ \sa Q_DECLARE_JNI_CLASS
+*/
+
+/*!
+ \macro Q_DECLARE_JNI_CLASS(Type, JavaSignature)
+ \relates QtJniTypes
+ \since 6.8
+
+ Declares a C++ type \a Type in the QtJniTypes namespace that wraps the Java
+ class \a JavaSignature. The Java class name in \a JavaSignature needs to be
+ fully qualified, using \c{/} as the separator.
+
+ \code
+ Q_DECLARE_JNI_CLASS(File, "java/io/File")
+ Q_DECLARE_JNI_CLASS(FileWriter, "java/io/FileWriter")
+ \endcode
+
+ The C++ classes \c{QtJniTypes::File} and \c{QtJniTypes::FileWriter} are
+ then QJniObject-like types that can be used to instantiate the
+ corresponding Java class, to call methods, and to pass such instances
+ through QJniObject variadic template methods with automatic, compile-time
+ signature deduction.
+
+ \code
+ using namespace QtJniTypes;
+
+ File file("path/to/file"); // instantiates the java.io.File type in Java
+ if (file.callMethod<bool>("createNewFile")) {
+ FileWriter writer(file); // instantiates a java.io.FileWriter that operates on file
+ writer.callMethod("write", 42);
+ }
+ \endcode
+
+ In addition to the QJniObject API, those C++ classes also have a static
+ \c{registerNativeMethods} member function that can be used like this:
+
+ \code
+ QtJniTypes::File::registerNativeMethods({
+ Q_JNI_NATIVE_METHOD(freeFunction)
+ });
+ \endcode
+
+ \sa Q_DECLARE_JNI_NATIVE_METHOD, Q_JNI_NATIVE_METHOD
+*/
+
+/*!
+ \macro Q_DECLARE_JNI_NATIVE_METHOD(Method)
+ \relates QtJniTypes
+ \since 6.8
+
+ Declares the free C or C++ function \a Method as a native method. The
+ method can later be registered with the JNI framework using
+ QJniEnvironment::registerNativeMethod() with the help of the
+ Q_JNI_NATIVE_METHOD macro.
+
+//! [register-free-function]
+ \code
+ // C++ side
+
+ Q_DECLARE_JNI_CLASS(MyJavaType, "my/java/Type")
+
+ static void nativeFunction(JNIEnv *env, jobject thiz, jlong id)
+ {
+ // ...
+ }
+ Q_DECLARE_JNI_NATIVE_METHOD(nativeFunction)
+
+ Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
+ {
+ QJniEnvironment env;
+ env.registerNativeMethods<QtJniTypes::MyJavaType>({
+ Q_JNI_NATIVE_METHOD(nativeFunction)
+ });
+ }
+
+ // Java side
+ public class MyJavaType
+ {
+ native public nativeFunction(long id);
+ }
+ \endcode
+//! [register-free-function]
+
+ \sa Q_JNI_NATIVE_METHOD, Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE
+*/
+
+/*!
+ \macro Q_DECLARE_JNI_NATIVE_METHOD(Method, JavaName)
+ \relates QtJniTypes
+ \overload
+ \since 6.8
+
+ Declares the free C or C++ function \a Method as a native method that's
+ available in Java as \a JavaName. The method can later be registered with
+ the JNI framework using QJniEnvironment::registerNativeMethod() with the
+ help of the Q_JNI_NATIVE_METHOD macro.
+
+ \sa Q_JNI_NATIVE_METHOD, Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE
+*/
+
+/*!
+ \macro Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(Method)
+ \relates QtJniTypes
+ \since 6.8
+
+ Declares the C++ static class member function \a Method as a native method.
+ The method can later be registered with the JNI framework using
+ QJniEnvironment::registerNativeMethod() with the help of the
+ Q_JNI_NATIVE_SCOPED_METHOD macro.
+
+//! [register-scoped-function]
+ \code
+ class NativeHandler
+ {
+ // ...
+ private:
+ static void handleChange(JNIEnv*, jobject, jlong id);
+ Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(handleChange)
+ };
+
+ \dots
+ QJniEnvironment env;
+ env.registerNativeMethods<QtJniTypes::MyJavaType>({
+ Q_JNI_NATIVE_SCOPED_METHOD(handleChange, NativeHandler)
+ });
+ \endcode
+//! [register-scoped-function]
+
+ \sa Q_DECLARE_JNI_NATIVE_METHOD, Q_JNI_NATIVE_SCOPED_METHOD
+*/
+
+/*!
+ \macro Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE(Method, JavaName)
+ \relates QtJniTypes
+ \overload
+ \since 6.8
+
+ Declares the C++ static class member function \a Method as a native method
+ that's available in Java as \a JavaName. The method can later be registered
+ with the JNI framework using QJniEnvironment::registerNativeMethod() with
+ the help of the Q_JNI_NATIVE_METHOD macro.
+
+ \sa Q_DECLARE_JNI_NATIVE_METHOD, Q_JNI_NATIVE_SCOPED_METHOD
+*/
+
+/*!
+ \macro Q_JNI_NATIVE_METHOD(Method)
+ \relates QtJniTypes
+ \since 6.8
+
+ Makes the previously \l{Q_DECLARE_JNI_NATIVE_METHOD}{declared} native
+ method \a Method available for registration with the JNI framework. Use
+ this macro when registering the method with JNI using
+ QJniEnvironment::registerNativeMethod().
+
+ \code
+ Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
+ {
+ QJniEnvironment env;
+ env.registerNativeMethods<QtJniTypes::MyJavaType>({
+ Q_JNI_NATIVE_METHOD(nativeFunction)
+ });
+ }
+ \endcode
+
+ \sa Q_DECLARE_JNI_NATIVE_METHOD
+*/
+
+/*!
+ \macro Q_JNI_NATIVE_SCOPED_METHOD(Method, Scope)
+ \relates QtJniTypes
+ \since 6.8
+
+ Makes the previously
+ \l{Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE}{declared} native method
+ \a Method in scope \a Scope available for registration with the JNI framework.
+ Use this macro when registering the method with JNI using
+ QJniEnvironment::registerNativeMethod().
+
+ \sa Q_JNI_NATIVE_METHOD, Q_DECLARE_JNI_NATIVE_METHOD_IN_CURRENT_SCOPE
+*/
diff --git a/src/corelib/doc/src/json.qdoc b/src/corelib/doc/src/json.qdoc
index 3097075eb9..98ae202cfa 100644
--- a/src/corelib/doc/src/json.qdoc
+++ b/src/corelib/doc/src/json.qdoc
@@ -6,7 +6,7 @@
\title JSON Support in Qt
\ingroup qt-basic-concepts
\brief An overview of JSON support in Qt.
-
+ \ingroup explanations-dataprocessingandio
\ingroup frameworks-technologies
\keyword JSON
@@ -73,8 +73,7 @@
A valid JSON document is either an array or an object, so a document always starts
with a square or curly bracket.
- \sa {JSON Save Game Example}
-
+ \sa {Saving and Loading a Game}
\section1 The JSON Classes
@@ -82,5 +81,4 @@
\l{Implicit Sharing}{implicitly shared classes}.
JSON support in Qt consists of these classes:
-
*/
diff --git a/src/corelib/doc/src/objectmodel/bindableproperties.qdoc b/src/corelib/doc/src/objectmodel/bindableproperties.qdoc
index d6f96f6579..9b3ea6ae66 100644
--- a/src/corelib/doc/src/objectmodel/bindableproperties.qdoc
+++ b/src/corelib/doc/src/objectmodel/bindableproperties.qdoc
@@ -32,7 +32,7 @@
different objects.
The \l {Introductory Example} below demonstrates the usage of bindable
- properties in C++ code. You can also check \l {Bindable Properties Example}
+ properties in C++ code. You can also check \l {Bindable Properties} example
to see how the bindable properties can help to improve your code.
\section1 Introductory Example
@@ -256,8 +256,8 @@
Q_PROPERTYs without \c BINDABLE can also be bound and be used in binding expressions,
as long as they define a \c NOTIFY signal. You must wrap the property in a \l QBindable
using the \c {QBindable(QObject* obj, const char* property)} constructor. Then, the
- property can be bound using \c \l QBindable::setBinding() or used in a binding
- expression via \c \l QBindable::value(). You must use \c QBindable::value() in binding
+ property can be bound using \l QBindable::setBinding() or used in a binding
+ expression via \l QBindable::value(). You must use \c QBindable::value() in binding
expressions instead of the normal property \c READ function (or \c MEMBER) to enable
dependency tracking if the property is not \c BINDABLE.
diff --git a/src/corelib/doc/src/objectmodel/metaobjects.qdoc b/src/corelib/doc/src/objectmodel/metaobjects.qdoc
index 62226ca466..44f574816e 100644
--- a/src/corelib/doc/src/objectmodel/metaobjects.qdoc
+++ b/src/corelib/doc/src/objectmodel/metaobjects.qdoc
@@ -5,7 +5,7 @@
\page metaobjects.html
\title The Meta-Object System
\brief An overview of Qt's meta-object system and introspection capabilities.
-
+ \ingroup explanations-basics
\ingroup qt-basic-concepts
\keyword meta-object
\keyword Meta-Object System
@@ -19,8 +19,7 @@
\list 1
\li The \l QObject class provides a base class for objects that can
take advantage of the meta-object system.
- \li The Q_OBJECT macro inside the private section of the class
- declaration is used to enable meta-object features, such as
+ \li The Q_OBJECT macro is used to enable meta-object features, such as
dynamic properties, signals, and slots.
\li The \l{moc}{Meta-Object Compiler} (\c moc) supplies each
QObject subclass with the necessary code to implement
diff --git a/src/corelib/doc/src/objectmodel/properties.qdoc b/src/corelib/doc/src/objectmodel/properties.qdoc
index eef2df7028..0e66c8445c 100644
--- a/src/corelib/doc/src/objectmodel/properties.qdoc
+++ b/src/corelib/doc/src/objectmodel/properties.qdoc
@@ -5,7 +5,7 @@
\page properties.html
\title The Property System
\brief An overview of Qt's property system.
-
+ \ingroup explanations-basics
\ingroup qt-basic-concepts
\keyword Qt's Property System
@@ -93,7 +93,7 @@
\li The \c DESIGNABLE attribute indicates whether the property
should be visible in the property editor of GUI design tool (e.g.,
- \l {Qt Designer Manual}{Qt Designer}). Most properties are \c DESIGNABLE
+ \l {Qt Widgets Designer Manual}{\QD}). Most properties are \c DESIGNABLE
(default true). Valid values are true and false.
\li The \c SCRIPTABLE attribute indicates whether this property
@@ -186,12 +186,11 @@
\section1 A Simple Example
- Suppose we have a class MyClass, which is derived from QObject and
- which uses the Q_OBJECT macro in its private section. We want to
- declare a property in MyClass to keep track of a priority
- value. The name of the property will be \e priority, and its type
- will be an enumeration type named \e Priority, which is defined in
- MyClass.
+ Suppose we have a class \c MyClass, which is derived from QObject and which
+ uses the Q_OBJECT macro. We want to declare a property in \c MyClass to keep
+ track of a priority value. The name of the property will be \c priority, and
+ its type will be an enumeration type named \c Priority, which is defined in
+ \c MyClass.
We declare the property with the Q_PROPERTY() macro in the private
section of the class. The required \c READ function is named \c
@@ -200,7 +199,7 @@
System} using the Q_ENUM() macro. Registering an enumeration type
makes the enumerator names available for use in calls to
QObject::setProperty(). We must also provide our own declarations
- for the \c READ and \c WRITE functions. The declaration of MyClass
+ for the \c READ and \c WRITE functions. The declaration of \c MyClass
then might look like this:
\snippet code/doc_src_properties.cpp 5
@@ -208,26 +207,29 @@
The \c READ function is const and returns the property type. The
\c WRITE function returns void and has exactly one parameter of
the property type. The meta-object compiler enforces these
- requirements.
+ requirements. The equality check in the \c WRITE function, while not
+ mandatory, is good practice as there is no point in notifying and
+ potentially forcing re-evaluation in other places if nothing has
+ changed.
- Given a pointer to an instance of MyClass or a pointer to a
- QObject that is an instance of MyClass, we have two ways to set
+ Given a pointer to an instance of \c MyClass or a pointer to a
+ QObject that is an instance of \c MyClass, we have two ways to set
its priority property:
\snippet code/doc_src_properties.cpp 6
In the example, the enumeration type that is the property type is
- declared in MyClass and registered with the \l{Meta-Object System}
+ declared in \c MyClass and registered with the \l{Meta-Object System}
using the Q_ENUM() macro. This makes the enumeration values
- available as strings for use as in the call to \l{QObject::}{setProperty()}. Had
- the enumeration type been declared in another class, its fully
+ available as strings for use as in the call to \l{QObject::}{setProperty()}.
+ Had the enumeration type been declared in another class, its fully
qualified name (i.e., OtherClass::Priority) would be required, and
that other class would also have to inherit QObject and register
the enumeration type there using the Q_ENUM() macro.
A similar macro, Q_FLAG(), is also available. Like Q_ENUM(), it
registers an enumeration type, but it marks the type as being a
- set of \e flags, i.e. values that can be OR'd together. An I/O
+ set of \e flags, i.e., values that can be OR'd together. An I/O
class might have enumeration values \c Read and \c Write and then
QObject::setProperty() could accept \c{Read | Write}. Q_FLAG()
should be used to register this enumeration type.
@@ -274,7 +276,9 @@
Connected to the property system is an additional macro,
Q_CLASSINFO(), that can be used to attach additional
- \e{name}--\e{value} pairs to a class's meta-object, for example:
+ \e{name}--\e{value} pairs to a class's meta-object. This is
+ used for instance to mark a property as the \e default one
+ in the context of \l{QML Object Types}:
\snippet code/doc_src_properties.cpp 7
@@ -296,5 +300,5 @@
and the general tips on implementing and using
\l {Qt Bindable Properties}{bindable properties}.
- \sa {Qt Bindable Properties}
+ \sa {Qt Bindable Properties}, {Defining QML Types from C++}
*/
diff --git a/src/corelib/doc/src/objectmodel/signalsandslots.qdoc b/src/corelib/doc/src/objectmodel/signalsandslots.qdoc
index 1b427f5775..f0eeb20048 100644
--- a/src/corelib/doc/src/objectmodel/signalsandslots.qdoc
+++ b/src/corelib/doc/src/objectmodel/signalsandslots.qdoc
@@ -8,7 +8,7 @@
\ingroup qt-basic-concepts
\brief An overview of Qt's signals and slots inter-object
communication mechanism.
-
+ \ingroup explanations-basics
Signals and slots are used for communication between objects. The
signals and slots mechanism is a central feature of Qt and
probably the part that differs most from the features provided by
@@ -109,8 +109,7 @@
when the signal is emitted.
Signals are automatically generated by the \l moc and must not be
- implemented in the \c .cpp file. They can never have return types
- (i.e. use \c void).
+ implemented in the \c .cpp file.
A note about arguments: Our experience shows that signals and slots
are more reusable if they do not use special types. If
@@ -297,8 +296,7 @@
callbacks, you'd have to find five different names and keep track
of the types yourself.
- \sa QLCDNumber, QObject::connect(), {Digital Clock Example},
- {Tetrix Example}
+ \sa QLCDNumber, QObject::connect()
\section1 Signals And Slots With Default Arguments
diff --git a/src/corelib/doc/src/qt6-changes.qdoc b/src/corelib/doc/src/qt6-changes.qdoc
index 5073a72d6a..011568ef75 100644
--- a/src/corelib/doc/src/qt6-changes.qdoc
+++ b/src/corelib/doc/src/qt6-changes.qdoc
@@ -5,7 +5,7 @@
\page qtcore-changes-qt6.html
\title Changes to Qt Core
\ingroup changes-qt-5-to-6
- \brief Migrate Qt Core to Qt 6.
+ \brief Changes to containers, strings, serialization and I/O classes.
Qt 6 is a result of the conscious effort to make the framework more
efficient and easy to use.
diff --git a/src/corelib/doc/src/qtcore-index.qdoc b/src/corelib/doc/src/qtcore-index.qdoc
index 99cc114d64..38452e1b2b 100644
--- a/src/corelib/doc/src/qtcore-index.qdoc
+++ b/src/corelib/doc/src/qtcore-index.qdoc
@@ -76,8 +76,10 @@
\li \l{The Animation Framework}
\li \l{JSON Support in Qt}
\li \l{CBOR Support in Qt}
+ \li \l{Inter-Process Communication}
\li \l{How to Create Qt Plugins}
\li \l{The Event System}
+ \li \l{Application Permissions}
\endlist
\section1 Reference
diff --git a/src/corelib/doc/src/qtcore.qdoc b/src/corelib/doc/src/qtcore.qdoc
index 2ef705dd75..a46add1342 100644
--- a/src/corelib/doc/src/qtcore.qdoc
+++ b/src/corelib/doc/src/qtcore.qdoc
@@ -18,9 +18,17 @@
/*!
\module QtCorePrivate
\title Qt Core Private C++ Classes
- \qtcmakepackage CorePrivate
\qtvariable core-private
-
- \brief Provides private core functionality.
\preliminary
+ \brief Provides private core functionality.
+
+//! [qtcoreprivate-usage]
+ When building with CMake, use the following commands to use
+ private Qt Core APIs:
+
+ \badcode
+ find_package(Qt6 REQUIRED COMPONENTS Core)
+ target_link_libraries(mytarget PRIVATE Qt6::CorePrivate)
+ \endcode
+//! [qtcoreprivate-usage]
*/
diff --git a/src/corelib/doc/src/qtserialization.qdoc b/src/corelib/doc/src/qtserialization.qdoc
new file mode 100644
index 0000000000..14ee5e7a9c
--- /dev/null
+++ b/src/corelib/doc/src/qtserialization.qdoc
@@ -0,0 +1,145 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \page qtserialization.html
+ \title Qt Serialization
+ \brief Serializations provided by Qt API
+
+ The purpose of serialization is to save the state of an object to be able to
+ recreate it when needed. It allows you to perform actions like:
+
+ \list
+ \li Sending the object to a remote application by using a web service
+ \li Passing the object as a JSON or XML string
+ \li Saving and restoring user information or sharing it across applications
+ \endlist
+
+ The Qt API provides support for serialization for several use cases:
+
+ \list
+ \li \l JSON support in Qt provides an easy to use C++ API to parse, modify
+ and save JSON data. \l {CBOR} {CBOR Support in Qt} is a compact form
+ of binary data encoding that is a superset of JSON.
+ \li \l QDataStream provides serialization of binary data to a QIODevice
+ \li \l {Qt XML C++ Classes} provide C++ implementations of the \l {XML Streaming}
+ and DOM standards for XML
+ \li \l CBOR is Qt's implementation for the CBOR serialization format.
+ \li \l QSettings provides a way of serializing and storing platform independent
+ application settings.
+ \endlist
+
+ \section1 Advantages of JSON and CBOR
+
+ When you use \l JSON information is stored in a QJsonObject and a QJsonDocument
+ takes care to stream values into a QByteArray.
+
+ For example
+ \code
+ QJsonObject jobject;
+ jobject["SensorID"] = m_id;
+ jobject["AmbientTemperature"] = m_ambientTemperature;
+ jobject["ObjectTemperature"] = m_objectTemperature;
+ jobject["AccelerometerX"] = m_accelerometerX;
+ jobject["AccelerometerY"] = m_accelerometerY;
+ jobject["AccelerometerZ"] = m_accelerometerZ;
+ jobject["Altitude"] = m_altitude;
+ jobject["Light"] = m_light;
+ jobject["Humidity"] = m_humidity;
+ QJsonDocument doc( jobject );
+
+ return doc.toJson();
+ \endcode
+
+ JSON has several advantages:
+
+ \list
+ \li Textual JSON is declarative, which makes it readable to humans
+ \li The information is structured
+ \li Exchanging generic information is easy
+ \li JSON allows extending messages with additional values
+ \li Many solutions exist to receive and parse JSON in cloud-based solutions
+ \endlist
+
+ \l CBOR is the Concise Binary Object Representation, a very compact form of
+ binary data encoding that is a superset of JSON. It was created by the IETF
+ Constrained RESTful Environments (CoRE) WG, which has been used in many new
+ RFCs. CBOR shares many of the advantages of JSON, but sacrifices human
+ readability for compactness.
+
+ \section1 Advantages of QDataStream Classes
+
+ \l QDataStream is a viable option when the whole flow of data is determined
+ and not about to change. In addition, both the reader and the writer of the
+ data must be written in Qt.
+
+ Adding support for this to a class requires two additional operators.
+ For example, for a class named SensorInformation:
+
+ \code
+ QDataStream &operator<<(QDataStream &, const SensorInformation &);
+ QDataStream &operator>>(QDataStream &, SensorInformation &);
+ \endcode
+
+ The implementation for the serialization is shown below:
+
+ \code
+ QDataStream &operator<<(QDataStream &out, const SensorInformation &item)
+ {
+ QDataStream::FloatingPointPrecision prev = out.floatingPointPrecision();
+ out.setFloatingPointPrecision(QDataStream::DoublePrecision);
+ out << item.m_id
+ << item.m_ambientTemperature
+ << item.m_objectTemperature
+ << item.m_accelerometerX
+ << item.m_accelerometerY
+ << item.m_accelerometerZ
+ << item.m_altitude
+ << item.m_light
+ << item.m_humidity;
+ out.setFloatingPointPrecision(prev);
+ return out;
+ }
+ \endcode
+
+ Deserialization works similarly, but using the \c {>>} operator.
+ For example, \c {out >> item.m_id}, and so on.
+
+ Usually, using QDataStream is faster than using textual JSON.
+
+ \section1 Advantages of Qt XML C++ Classes
+
+ Qt provides both DOM classes and stream-based classes to read and write
+ XML content.
+
+ Qt provides the QDomDocument class that represents the XML document and
+ two classes for reading and writing the XML through a simple streaming API:
+ QXmlStreamReader and QXmlStreamWriter.
+
+ \section2 The DOM XML Classes
+
+ QDomDocument class represents the entire XML document. It is the root of the
+ document tree and provides primary access to the document's data.
+
+ \section2 The Stream-Based XML Classes
+
+ A stream reader reports an XML document as a stream of tokens. This differs
+ from SAX as SAX applications provide handlers to receive XML events from the
+ parser, whereas the QXmlStreamReader drives the loop, pulling tokens from the
+ reader when they are needed. This pulling approach makes it possible to build
+ recursive descent parsers, allowing XML parsing code to be split into
+ different methods or classes.
+
+ QXmlStreamReader a parser for well-formed XML 1.0, excluding external parsed
+ entities. Hence, data provided to the stream reader adheres to the
+ W3C's criteria for well-formed XML, or an error will be raised. Functions
+ such as \c atEnd(), \c error(), and \c hasError() can be used to test for
+ such errors and obtain a description of them.
+
+ The QXmlStreamWriter is a streaming API that takes care of prefixing namespaces,
+ when the namespaceUri is specified when writing elements or attributes.
+
+ \section1 Classes that Provide Serialization
+
+ \annotatedlist qtserialization
+*/
diff --git a/src/corelib/doc/src/resource-system.qdoc b/src/corelib/doc/src/resource-system.qdoc
index 8cee601c67..7c7613c9b8 100644
--- a/src/corelib/doc/src/resource-system.qdoc
+++ b/src/corelib/doc/src/resource-system.qdoc
@@ -17,7 +17,7 @@
Most commonly, the resource files are embedded into your application
executable, or in libraries and plugins that are loaded by the application
executable. Alternatively, the resource files can also be stored in an
- \l{External Resource Files}{exernal resource file}.
+ \l{External Resource Files}{external resource file}.
The resource system is based on tight cooperation between Qt's \l rcc
resource compiler, the build system, and the Qt runtime API.
@@ -59,8 +59,8 @@
the \c .qrc file.
The path is also used by default to identify the file's content at runtime.
- That is, the file \c copy.png will be available in the resource system as
- \c{:/images/copy.png} or \c{qrc:/images/copy.png}.
+ That is, the file \c titlebarLeft.png will be available in the resource system as
+ \c{:/res/titlebarLeft.png} or \c{qrc:/res/titlebarLeft.png}.
To override this default run-time name, see \l{Prefixes} and \l{Aliases}.
\e{Qt Creator}, \e{Qt Design Studio}, \QD, and \e{Qt Visual Studio Tools}
@@ -102,22 +102,16 @@
variable. If you add a \c .qrc file path to the variable, the listed
resource files will be embedded into the generated library or executable:
- \snippet resource-system/application.pro 0
-
- For simple applications, it is also possible to let qmake generate the
- \c .qrc file for you, avoiding the need for an additional file to be
- maintained:
-
- \snippet resource-system/application.pro 1
+ \snippet resource-system/application.pro qrc
This creates a resource of several \c{.png} files, that are addressable
- like this: \c{":/images/copy.png"}.
+ like this: \c{":/res/titlebarLeft.png"}.
If the directory layout of the files you want to embed into the resource
doesn't match the expectations of the application, you can specify
\c{resources.base}. \c base is a path prefix that denotes the root point of
the file's alias. In the example above, if \c{resources.base} is set to
- \c{"images"}, then \c{copy.png} is addressable as \c{":/copy.png"}.
+ \c{"res"}, then \c{titlebarLeft.png} is addressable as \c{":/titlebarLeft.png"}.
\section1 Runtime API
@@ -136,9 +130,6 @@
\snippet resource-system/main.cpp url
- See the \l{mainwindows/application}{Application} example for an actual
- application that uses Qt's resource system to store its icons.
-
\section1 Advanced Topics
\section2 Prefixes
@@ -166,6 +157,25 @@
The file is from the application then only accessible as \c :/cut-img.png
or \c{qrc:/cut-img.png}.
+ \section2 Discarding the file contents
+
+ Sometimes you want to add a file node to the resource file system but
+ don't actually want to add the file contents. \c .qrc files allow this
+ by setting the \c empty attribute to \c{true}.
+
+ \snippet code/doc_src_resources.qdoc 4
+
+ The resulting file is then still accessible from the application, but
+ its contents are empty.
+
+ This is useful to strip QML source code from an application binary.
+
+ \note If you omit the QML source code from the binary, the QML engine has to
+ rely on the compilation units created by \l{qmlcachegen} or \l{qmlsc}.
+ Those are tied to the specific version of Qt they were built with. If you
+ change the version of Qt your application uses, they can't be loaded
+ anymore.
+
\section2 Language Selectors
Some resources need to change based on the user's locale, such as
@@ -197,14 +207,7 @@
resource file's content and metadata is then done after the compilation and
linking phase, through another rcc call.
- For qmake, this is enabled by adding \c resources_big to the \c CONFIG
- variable:
-
- \snippet resource-system/application.pro 2
-
- For CMake, you need to use the \l{qt_add_big_resources} function:
-
- \snippet resource-system/CMakeLists.txt qt_add_big_resources
+ For CMake, you need to use the \l{qt_add_big_resources} function.
\section2 External Resource Files
@@ -232,13 +235,13 @@
resource compiler \l rcc:
\code
- rcc -g python application.qrc > application_rc.py
+ rcc -g python mainwindow.qrc > mainwindow_rc.py
\endcode
The module can then be imported in the application:
\code
- import application_rc.py
+ import mainwindow_rc.py
\endcode
\section2 Compression
diff --git a/src/corelib/doc/src/timers.qdoc b/src/corelib/doc/src/timers.qdoc
index c9ad054b17..dc205a47b9 100644
--- a/src/corelib/doc/src/timers.qdoc
+++ b/src/corelib/doc/src/timers.qdoc
@@ -6,17 +6,17 @@
\title Timers
\brief How to use Qt timers in your application.
- \ingroup best-practices
+ \ingroup how-to
QObject, the base class of all Qt objects, provides the basic
timer support in Qt. With QObject::startTimer(), you start a
timer with an interval in milliseconds as argument. The function
- returns a unique integer timer ID. The timer will now fire at
+ returns a unique integral timer ID. The timer will then fire at
regular intervals until you explicitly call QObject::killTimer()
- with the timer ID.
+ with that timer ID.
For this mechanism to work, the application must run in an event
- loop. You start an event loop with QApplication::exec(). When a
+ loop. You cat start an event loop with QApplication::exec(). When a
timer fires, the application sends a QTimerEvent, and the flow of
control leaves the event loop until the timer event is processed.
This implies that a timer cannot fire while your application is
@@ -31,69 +31,65 @@
stop all timers in the object's thread; it is not possible to
start timers for objects in another thread.
- The upper limit for the interval value is determined by the number
- of milliseconds that can be specified in a signed integer
- (in practice, this is a period of just over 24 days). The accuracy
- depends on the underlying operating system. Windows 2000 has 15
- millisecond accuracy; other systems that we have tested can handle
- 1 millisecond intervals.
-
- The main API for the timer functionality is QTimer. That class
- provides regular timers that emit a signal when the timer fires, and
- inherits QObject so that it fits well into the ownership structure
- of most Qt programs. The normal way of using it is like this:
-
- \snippet timers/timers.cpp 0
- \snippet timers/timers.cpp 1
- \snippet timers/timers.cpp 2
-
- The QTimer object is made into a child of \c this object so that,
- when \c this object is deleted, the timer is deleted too.
- Next, its \l{QTimer::}{timeout()} signal is connected to the slot
- that will do the work, it is started with a value of 1000
- milliseconds, indicating that it will time out every second.
-
- QTimer also provides a static function for single-shot timers.
+ The main API for the timer functionality was \l QTimer. QTimer stores
+ the interval in a signed integer, which limits the maximum interval it
+ supports to the number of milliseconds that can fit in a signed integer
+ (in practice, this is a period of around 24 days).
+
+ Qt 6.8 introduced the \l QChronoTimer class to replace QTimer. QChronoTimer
+ stores the interval as \c std::chrono::nanoseconds, which means that
+ the maximum interval it supports is around 292 years. This mitigates
+ the chances of integer overflow that QTimer had if the interval was more
+ than \c{std::numeric_limits<int>::max()}.
+
+ The accuracy of the timers depends on the underlying operating system.
+ Windows 2000 has 15ms accuracy; other systems that we have tested can
+ handle 1ms intervals.
+
+ QChronoTimer provides regular timers that emit a signal when the timer
+ fires, and inherits from QObject so that it fits well into the ownership
+ structure of most Qt programs. The normal way of using it is like this:
+
+ \snippet timers/timers.cpp timer-interval-in-ctor
+ \snippet timers/timers.cpp timer-setinterval
+
+ The QChronoTimer object is made into a child of the \c this object so
+ that, when \c this is destroyed, the timer is destroyed too. Next, the
+ \l{QChronoTimer::}{timeout()} signal is connected to the slot that will
+ do the work, the timer interval can be either passed to the constructor,
+ or set later on with setInterval().
+
+ QChronoTimer also provides static functions for single-shot timers.
For example:
- \snippet timers/timers.cpp 3
+ \snippet timers/timers.cpp qchronotimer-singleshot
- 200 milliseconds (0.2 seconds) after this line of code is
- executed, the \c updateCaption() slot will be called.
+ 200ms after this line of code is executed, the \c updateCaption() slot
+ will be called.
- For QTimer to work, you must have an event loop in your
- application; that is, you must call QCoreApplication::exec()
- somewhere. Timer events will be delivered only while the event
- loop is running.
+ For QChronoTimer to work, you must have an event loop in your application;
+ that is, you must call QCoreApplication::exec() somewhere. Timer events
+ will be delivered only while the event loop is running.
- In multithreaded applications, you can use QTimer in any thread
- that has an event loop. To start an event loop from a non-GUI
- thread, use QThread::exec(). Qt uses the timer's
- \l{QObject::thread()}{thread affinity} to determine which thread
- will emit the \l{QTimer::}{timeout()} signal. Because of this, you
- must start and stop the timer in its thread; it is not possible to
- start a timer from another thread.
-
- The \l{widgets/analogclock}{Analog Clock} example shows how to use
- QTimer to redraw a widget at regular intervals. From \c{AnalogClock}'s
- implementation:
-
- \snippet timers/analogclock.cpp 0
- \snippet timers/analogclock.cpp 2
- \snippet timers/analogclock.cpp 3
- \snippet timers/analogclock.cpp 4
- \snippet timers/analogclock.cpp 5
- \snippet timers/analogclock.cpp 6
- \dots
- \snippet timers/analogclock.cpp 7
-
- Every second, QTimer will call the QWidget::update() slot to
+ In multithreaded applications, you can use QChronoTimer in any thread
+ that has an event loop. To start an event loop from a non-GUI thread, use
+ QThread::exec(). Qt uses the timer's \l{QObject::thread()}{thread affinity}
+ to determine which thread will emit the \l{QChronoTimer::}{timeout()}
+ signal. Because of this, you must start and stop the timer in its thread;
+ it is not possible to start a timer from another thread.
+
+ The \l{widgets/analogclock}{Analog Clock} example shows how to
+ use QChronoTimer to redraw a widget at regular intervals. From
+ \c{AnalogClock}'s implementation:
+
+ \snippet timers/analogclock.cpp analogclock-qchronotimer
+
+ Every second, QChronoTimer will call the QWidget::update() slot to
refresh the clock's display.
If you already have a QObject subclass and want an easy
optimization, you can use QBasicTimer instead of QTimer. With
QBasicTimer, you must reimplement
\l{QObject::timerEvent()}{timerEvent()} in your QObject subclass
- and handle the timeout there. The \l{widgets/wiggly}{Wiggly}
- example shows how to use QBasicTimer.
+ and handle the timeout there.
*/