diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-02-11 10:34:21 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-02-15 12:20:16 +0000 |
commit | 37a25fce94976ab2a0f94abe43f1ed6ad950672f (patch) | |
tree | 412929788ce8f4fa7d6481b74f2c471839a587ab /tests/auto/gui/util | |
parent | 06e45cbd6a2e09bc32cb1c9aa3779d6bd5282c45 (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 'tests/auto/gui/util')
-rw-r--r-- | tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp b/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp index 7446f8ed9f..4df34280b0 100644 --- a/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp +++ b/tests/auto/gui/util/qdesktopservices/tst_qdesktopservices.cpp @@ -65,6 +65,10 @@ public slots: } }; +#if QT_VERSION < QT_VERSION_CHECK(6, 6, 0) +# define CAN_IMPLICITLY_UNSET +#endif + void tst_qdesktopservices::handlers() { MyUrlHandler fooHandler; @@ -72,6 +76,12 @@ void tst_qdesktopservices::handlers() QDesktopServices::setUrlHandler(QString("foo"), &fooHandler, "handle"); QDesktopServices::setUrlHandler(QString("bar"), &barHandler, "handle"); +#ifndef CAN_IMPLICITLY_UNSET + const auto unsetHandlers = qScopeGuard([] { + QDesktopServices::unsetUrlHandler(u"bar"_qs); + QDesktopServices::unsetUrlHandler(u"foo"_qs); + }); +#endif QUrl fooUrl("foo://blub/meh"); QUrl barUrl("bar://hmm/hmmmm"); @@ -81,6 +91,15 @@ void tst_qdesktopservices::handlers() QCOMPARE(fooHandler.lastHandledUrl.toString(), fooUrl.toString()); QCOMPARE(barHandler.lastHandledUrl.toString(), barUrl.toString()); + +#ifdef CAN_IMPLICITLY_UNSET + for (int i = 0; i < 2; ++i) + QTest::ignoreMessage(QtWarningMsg, + "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."); +#endif } QTEST_MAIN(tst_qdesktopservices) |