summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2023-12-03 22:19:02 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2024-03-13 13:08:29 +0100
commit3a6c8e02b6d1b0574da52b0087092d0c74aa92c1 (patch)
tree78c006c0659e2b06bf0363a1a973661e4415613f
parent03baf08d2bb99bf234d5e051691a57937fa935d7 (diff)
Long live QT_ENABLE_STRICT_MODE_UP_TO
We already have fine-grained macros to individually disable APIs that we consider "suboptimal" or "dangerous". This commit adds a shortcut for the user to set all such macros in one go. QT_ENABLE_STRICT_MODE_UP_TO is versioned, just like QT_DISABLE_DEPRECATED_UP_TO; the idea is that users should set it to the minimum Qt version they want to support. Also, if QT_DISABLE_DEPRECATED_UP_TO is not set, then QT_ENABLE_STRICT_MODE_UP_TO will set it as well, to the same value. [ChangeLog][QtCore][QtGlobal] Added the QT_ENABLE_STRICT_MODE_UP_TO macro. Change-Id: I5466465986104e047a6a86369928be9294f24ab7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/corelib/doc/src/foreach-keyword.qdoc11
-rw-r--r--src/corelib/global/qglobal.cpp45
-rw-r--r--src/corelib/global/qtconfigmacros.h31
3 files changed, 87 insertions, 0 deletions
diff --git a/src/corelib/doc/src/foreach-keyword.qdoc b/src/corelib/doc/src/foreach-keyword.qdoc
index e0109f1f0c..b3a4482528 100644
--- a/src/corelib/doc/src/foreach-keyword.qdoc
+++ b/src/corelib/doc/src/foreach-keyword.qdoc
@@ -73,4 +73,15 @@
\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
+
+ Defining this macro removes the availability of Qt's \c foreach
+ loop.
*/
diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp
index 276f8ab1ad..9a7531e4c5 100644
--- a/src/corelib/global/qglobal.cpp
+++ b/src/corelib/global/qglobal.cpp
@@ -310,6 +310,51 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters)
qMove takes an rvalue reference to its parameter \a x, and converts it to an xvalue.
*/
+/*!
+ \macro QT_ENABLE_STRICT_MODE_UP_TO
+ \relates <QtGlobal>
+ \since 6.8
+
+ Defining this macro will disable a number of Qt APIs that are
+ deemed suboptimal or dangerous.
+
+ This macro's value must be set to a Qt version, using
+ \l{QT_VERSION_CHECK}'s encoding. For instance, in order to set it
+ to Qt 6.6, define \c{QT_ENABLE_STRICT_MODE_UP_TO=0x060600}.
+ This will disable only the APIs introduced in versions up to (and
+ including) the specified Qt version.
+
+ If the \l QT_DISABLE_DEPRECATED_UP_TO macro is \e not defined,
+ then QT_ENABLE_STRICT_MODE_UP_TO will define it as well,
+ to the same value.
+
+ This macro should always be set to the minimum Qt version that
+ your project wants to support.
+
+ The APIs disabled by this macro are listed in the table below,
+ together with the minimum value to use in order to disable them.
+
+ \table
+ \header \li Version \li Disabled APIs
+ \row \li 6.0.0 \li \l{foreach-keyword}{foreach} (see \l{QT_NO_FOREACH})
+ \row \li 6.0.0 \li QString constructors from \c{const char *} (see \l{QT_NO_CAST_FROM_ASCII})
+ \row \li 6.0.0 \li QString conversions towards \c{const char *} / QByteArray (see \l{QT_NO_CAST_TO_ASCII})
+ \row \li 6.0.0 \li QByteArray implicit conversions towards \c{const char *} (see \l{QT_NO_CAST_FROM_BYTEARRAY})
+ \row \li 6.0.0 \li QUrl implicit conversions from QString (see \l{QT_NO_URL_CAST_FROM_STRING})
+ \row \li 6.0.0 \li Allowing narrowing conversions in signal-slot connections (see \l{QT_NO_NARROWING_CONVERSIONS_IN_CONNECT})
+ \row \li 6.0.0 \li Java-style iterators for Qt containers
+ \row \li 6.6.0 \li The qExchange() function (see \l{QT_NO_QEXCHANGE})
+ \row \li 6.7.0 \li Overloads of QObject::connect that do not take a context object (see \l{QT_NO_CONTEXTLESS_CONNECT})
+ \row \li 6.8.0 \li The qAsConst() function (see \l{QT_NO_QASCONST})
+ \endtable
+
+ Moreover, individual APIs may also get disabled as part of the
+ setting of QT_DISABLE_DEPRECATED_UP_TO. Please refer to each class'
+ documentation for more details.
+
+ \sa QT_DISABLE_DEPRECATED_UP_TO, QT_NO_KEYWORDS, QT_VERSION_CHECK
+*/
+
namespace QtPrivate {
Q_LOGGING_CATEGORY(lcNativeInterface, "qt.nativeinterface")
}
diff --git a/src/corelib/global/qtconfigmacros.h b/src/corelib/global/qtconfigmacros.h
index 9d185a0aa3..6080562ab4 100644
--- a/src/corelib/global/qtconfigmacros.h
+++ b/src/corelib/global/qtconfigmacros.h
@@ -155,4 +155,35 @@ namespace QT_NAMESPACE {}
# define QT_END_MOC_NAMESPACE
#endif
+/*
+ Strict mode
+*/
+#ifdef QT_ENABLE_STRICT_MODE_UP_TO
+#ifndef QT_DISABLE_DEPRECATED_UP_TO
+# define QT_DISABLE_DEPRECATED_UP_TO QT_ENABLE_STRICT_MODE_UP_TO
+#endif
+
+#if QT_ENABLE_STRICT_MODE_UP_TO >= QT_VERSION_CHECK(6, 0, 0)
+# define QT_NO_FOREACH
+# define QT_NO_CAST_FROM_ASCII
+# define QT_NO_CAST_TO_ASCII
+# define QT_NO_CAST_FROM_BYTEARRAY
+# define QT_NO_URL_CAST_FROM_STRING
+# define QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
+# define QT_NO_JAVA_STYLE_ITERATORS
+#endif // 6.0.0
+
+#if QT_ENABLE_STRICT_MODE_UP_TO >= QT_VERSION_CHECK(6, 6, 0)
+# define QT_NO_QEXCHANGE
+#endif // 6.6.0
+
+#if QT_ENABLE_STRICT_MODE_UP_TO >= QT_VERSION_CHECK(6, 7, 0)
+# define QT_NO_CONTEXTLESS_CONNECT
+#endif // 6.7.0
+
+#if QT_ENABLE_STRICT_MODE_UP_TO >= QT_VERSION_CHECK(6, 8, 0)
+# define QT_NO_QASCONST
+#endif // 6.8.0
+#endif // QT_ENABLE_STRICT_MODE_UP_TO
+
#endif /* QTCONFIGMACROS_H */