summaryrefslogtreecommitdiffstats
path: root/src/gui/util
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-02-11 10:34:21 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-02-15 12:20:16 +0000
commit37a25fce94976ab2a0f94abe43f1ed6ad950672f (patch)
tree412929788ce8f4fa7d6481b74f2c471839a587ab /src/gui/util
parent06e45cbd6a2e09bc32cb1c9aa3779d6bd5282c45 (diff)
QDesktopServices: deprecate destroying URL handlers w/o explicit unsetUrlHandler()
[ChangeLog][QtGui][QDesktopServices] URL handlers that have been passed to setUrlHandler() must now be removed by calling unsetUrlHandler() before they are destroyed. Relying on the handler's destructor to implicitly unset it is now deprecated, because it may already be in use by concurrent openUrl() calls. Support for implicit unsetting will be removed in 6.6 and, until then, a qWarning() is raised if it is exercised. Fixes: QTBUG-100775 Fixes: QTBUG-100779 Pick-to: 6.3 6.2 5.15 Change-Id: I0c4f91b78f847b135fdeb38766babc892bdc1379 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'src/gui/util')
-rw-r--r--src/gui/util/qdesktopservices.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/gui/util/qdesktopservices.cpp b/src/gui/util/qdesktopservices.cpp
index fd3761a473..8f237960d6 100644
--- a/src/gui/util/qdesktopservices.cpp
+++ b/src/gui/util/qdesktopservices.cpp
@@ -74,13 +74,16 @@ public:
typedef QHash<QString, Handler> HandlerHash;
HandlerHash handlers;
+#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
public Q_SLOTS:
void handlerDestroyed(QObject *handler);
+#endif
};
Q_GLOBAL_STATIC(QOpenUrlHandlerRegistry, handlerRegistry)
+#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
void QOpenUrlHandlerRegistry::handlerDestroyed(QObject *handler)
{
const auto lock = qt_scoped_lock(mutex);
@@ -88,11 +91,16 @@ void QOpenUrlHandlerRegistry::handlerDestroyed(QObject *handler)
while (it != handlers.end()) {
if (it->receiver == handler) {
it = handlers.erase(it);
+ qWarning("Please call QDesktopServices::unsetUrlHandler() before destroying a "
+ "registered URL handler object.\n"
+ "Support for destroying a registered URL handler object is deprecated, "
+ "and will be removed in Qt 6.6.");
} else {
++it;
}
}
}
+#endif
/*!
\class QDesktopServices
@@ -255,6 +263,10 @@ bool QDesktopServices::openUrl(const QUrl &url)
Note that the handler will always be called from within the same thread that
calls QDesktopServices::openUrl().
+ You must call unsetUrlHandler() before destroying the handler object, so
+ the destruction of the handler object does not overlap with concurrent
+ invocations of openUrl() using it.
+
\section1 iOS
To use this function for receiving data from other apps on iOS you also need to
@@ -323,14 +335,20 @@ void QDesktopServices::setUrlHandler(const QString &scheme, QObject *receiver, c
h.receiver = receiver;
h.name = method;
registry->handlers.insert(scheme.toLower(), h);
+#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0)
QObject::connect(receiver, SIGNAL(destroyed(QObject*)),
registry, SLOT(handlerDestroyed(QObject*)),
Qt::DirectConnection);
+#endif
}
/*!
Removes a previously set URL handler for the specified \a scheme.
+ Call this function before the handler object that was registered for \a scheme
+ is destroyed, to prevent concurrent openUrl() calls from continuing to call
+ the destroyed handler object.
+
\sa setUrlHandler()
*/
void QDesktopServices::unsetUrlHandler(const QString &scheme)