diff options
author | Volker Hilsheimer <[email protected]> | 2024-02-27 10:35:49 +0100 |
---|---|---|
committer | Volker Hilsheimer <[email protected]> | 2024-03-01 16:09:38 +0100 |
commit | fd5487188db787b7d35b3aff070a81a59cc68058 (patch) | |
tree | 86c7a958e7a4ba857dc717615b42470f72b9b508 | |
parent | 98a6de5e99838192d3140a7f9954c4eb0220a693 (diff) |
Windows: clean up System Tray Icon message icon
The handle is not owned by the Shell, we have to clear it up ourselves.
The documentation is not clear about how long the handle needs to be
kept alive, so store the icon when we create it as a member of the
private, and clean it up when it need to be recreated, or when the
QSystemTrayIcon instance gets destroyed.
Conflict resolution needed as 94809cdec004611bdb8531304e6c74761014876b
had not been cherry-picked back to 6.5.
Fixes: QTBUG-96348
Fixes: QTBUG-62945
Pick-to: 6.2 5.15
Change-Id: I6f93f29a415cde2cfe4e1b296295783c15b4da4b
Reviewed-by: Oliver Wolff <[email protected]>
(cherry picked from commit afb74a86d8cd1ac6463fa804300480967101d7d7)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
(cherry picked from commit 59ff87dc911840669699c0a09acb2fd7ffa012fe)
(cherry picked from commit 5bdb2bacefc8b09c8f5da0973e5d7f8720b777aa)
Reviewed-by: Volker Hilsheimer <[email protected]>
-rw-r--r-- | src/plugins/platforms/windows/qwindowssystemtrayicon.cpp | 10 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowssystemtrayicon.h | 1 |
2 files changed, 10 insertions, 1 deletions
diff --git a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp index e5065d51651..1023a8b70fc 100644 --- a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp +++ b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp @@ -225,6 +225,10 @@ void QWindowsSystemTrayIcon::showMessage(const QString &title, const QString &me size = largeIcon; } QPixmap pm = icon.pixmap(size); + if (m_hMessageIcon) { + DestroyIcon(m_hMessageIcon); + m_hMessageIcon = nullptr; + } if (pm.isNull()) { tnd.dwInfoFlags = NIIF_INFO; } else { @@ -233,7 +237,8 @@ void QWindowsSystemTrayIcon::showMessage(const QString &title, const QString &me pm.size().width(), pm.size().height(), size.width(), size.height()); pm = pm.scaled(size, Qt::IgnoreAspectRatio); } - tnd.hBalloonIcon = qt_pixmapToWinHICON(pm); + m_hMessageIcon = qt_pixmapToWinHICON(pm); + tnd.hBalloonIcon = m_hMessageIcon; } tnd.hWnd = m_hwnd; tnd.uTimeout = msecsIn <= 0 ? UINT(10000) : UINT(msecsIn); // 10s default @@ -291,7 +296,10 @@ void QWindowsSystemTrayIcon::ensureCleanup() } if (m_hIcon != nullptr) DestroyIcon(m_hIcon); + if (m_hMessageIcon != nullptr) + DestroyIcon(m_hMessageIcon); m_hIcon = nullptr; + m_hMessageIcon = nullptr; m_menu = nullptr; // externally owned m_toolTip.clear(); } diff --git a/src/plugins/platforms/windows/qwindowssystemtrayicon.h b/src/plugins/platforms/windows/qwindowssystemtrayicon.h index f962860366b..c341176d9b8 100644 --- a/src/plugins/platforms/windows/qwindowssystemtrayicon.h +++ b/src/plugins/platforms/windows/qwindowssystemtrayicon.h @@ -55,6 +55,7 @@ private: QString m_toolTip; HWND m_hwnd = nullptr; HICON m_hIcon = nullptr; + HICON m_hMessageIcon = nullptr; mutable QPointer<QWindowsPopupMenu> m_menu; bool m_ignoreNextMouseRelease = false; bool m_visible = false; |