From 6f995b5e246bd9cc56710fa9cebc6dbb7cb2b72f 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 6.7 Change-Id: I61f4e59f7309e2bb47b50a6ca6f3099ed9cd0af1 Reviewed-by: Tor Arne Vestbø --- .../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 e1961c9976..aa6be266da 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