QSystemTrayIcon: properly disconnect old menu in setContextMenu()

Amends 121a30ccef3b6306c1da4f415fe1305dbf2dd901
Fix the unfortunate mistake where oldMenu was not properly disconnected
from the contextMenuRequested() signal. This could lead to a situation
when several menus are displayed at the same time.

Fixes: QTBUG-78737
Change-Id: Ice59841724207192eacd5a52b644f83159e09913
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit b71aa3c661797a916effd29171665ea838816595)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 7ea394eed6f70d4fb9b8a094db7bff40ea04f6bd)
(cherry picked from commit 08dfed7e1cd2224e4bdcbe7fb275418eb8458ee6)
(cherry picked from commit 3db07109309ee18cc60dc09e4dcc10d9d5df69d5)
This commit is contained in:
Vladimir Belyavsky 2023-11-12 12:04:12 +03:00 committed by Qt Cherry-pick Bot
parent d5d7045065
commit 63a58e0720

View File

@ -208,7 +208,7 @@ void QSystemTrayIcon::setContextMenu(QMenu *menu)
if (oldMenu != menu && d->qpa_sys) {
// Show the QMenu-based menu for QPA plugins that do not provide native menus
if (oldMenu && !oldMenu->platformMenu())
QObject::disconnect(d->qpa_sys, &QPlatformSystemTrayIcon::contextMenuRequested, menu, nullptr);
QObject::disconnect(d->qpa_sys, &QPlatformSystemTrayIcon::contextMenuRequested, oldMenu, nullptr);
if (menu && !menu->platformMenu()) {
QObject::connect(d->qpa_sys, &QPlatformSystemTrayIcon::contextMenuRequested,
menu,