From 81395d94e9f6847029837b9980b92a10ac9bdb4d Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Fri, 12 Apr 2024 11:42:43 +0200 Subject: [PATCH] Windows: Prevent potential "crash" in setApplicationBadge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In some circumstances our application badge code seems to throw an exception. The issue is hard to reproduce but just catching the exception should be enough to fall back to the "non-winrt" version of the code. Fixes: QTBUG-117091 Pick-to: 6.5 Change-Id: I61f4e59f7309e2bb47b50a6ca6f3099ed9cd0af1 Reviewed-by: Tor Arne Vestbø (cherry picked from commit 6f995b5e246bd9cc56710fa9cebc6dbb7cb2b72f) Reviewed-by: Qt Cherry-pick Bot --- .../platforms/windows/qwindowsintegration.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp index 1ed5bf8330d..0bbf25054da 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.cpp +++ b/src/plugins/platforms/windows/qwindowsintegration.cpp @@ -625,12 +625,16 @@ void QWindowsIntegration::setApplicationBadge(qint64 number) // We prefer the native BadgeUpdater API, that allows us to set a number directly, // but it requires that the application has a package identity, and also doesn't // seem to work in all cases on < Windows 11. - if (isWindows11 && qt_win_hasPackageIdentity()) { - using namespace winrt::Windows::UI::Notifications; - auto badgeXml = BadgeUpdateManager::GetTemplateContent(BadgeTemplateType::BadgeNumber); - badgeXml.SelectSingleNode(L"//badge/@value").NodeValue(winrt::box_value(winrt::to_hstring(number))); - BadgeUpdateManager::CreateBadgeUpdaterForApplication().Update(BadgeNotification(badgeXml)); - return; + QT_TRY { + if (isWindows11 && qt_win_hasPackageIdentity()) { + using namespace winrt::Windows::UI::Notifications; + auto badgeXml = BadgeUpdateManager::GetTemplateContent(BadgeTemplateType::BadgeNumber); + badgeXml.SelectSingleNode(L"//badge/@value").NodeValue(winrt::box_value(winrt::to_hstring(number))); + BadgeUpdateManager::CreateBadgeUpdaterForApplication().Update(BadgeNotification(badgeXml)); + return; + } + } QT_CATCH(...) { + // fall back to win32 implementation } #endif