Details
Description
It seems like the method setContextMenu in QSystemTrayIcon class doesn't work correctly.
On Windows, after calling the setContextMenu, provided that another (not old) menu is added, when you click on the tray, both the old and the newly added menu appear instead of the expected only new menu.
I have a suspicion that the problem is in the wrong disconnect in the QSystemTrayIcon::setContextMenu method (in qsystemtrayicon.cpp). After some checks on the status of the old menu, the necessary disconnection occurs. But the problem is that disconnect occurs for the new (added) menu, not for the old one.
if (oldMenu && !oldMenu->platformMenu())
QObject::disconnect(d->qpa_sys, &QPlatformSystemTrayIcon::contextMenuRequested, menu, nullptr);
The attached file contains simple example. After pressing the first button ("Set Menu1 (red)") a red menu appears in the tray icon. But after pressing the second button ("Set Menu2 (blue)") a blue menu appears along with the red one.
This code was tested on 5.12.4 and 5.13.1 Qt versions.