1- // SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
1+ // SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd.
22//
33// SPDX-License-Identifier: GPL-3.0-or-later
44
@@ -28,7 +28,8 @@ TrayWidget::TrayWidget(QPointer<AbstractTrayProtocolHandler> handler)
2828 setWindowTitle (m_handler->id ());
2929 setFixedSize (trayIconSize, trayIconSize);
3030
31- m_handler->setParent (this );
31+ // Note: Do NOT set parent here - handler lifecycle is managed by QSharedPointer
32+ // Setting parent would cause double-delete when QSharedPointer destroys the handler
3233
3334 connect (m_handler, &AbstractTrayProtocolHandler::iconChanged, this , [this ](){update ();});
3435 connect (m_handler, &AbstractTrayProtocolHandler::overlayIconChanged, this , [this ](){update ();});
@@ -47,6 +48,9 @@ TrayWidget::~TrayWidget()
4748void TrayWidget::showEvent (QShowEvent* event)
4849{
4950 Q_UNUSED (event)
51+ if (!m_handler)
52+ return ;
53+
5054 m_handler->setWindow (window ());
5155 window ()->installEventFilter (m_handler);
5256 window ()->setMouseTracking (true );
@@ -56,6 +60,9 @@ void TrayWidget::paintEvent(QPaintEvent* event)
5660{
5761 Q_UNUSED (event)
5862
63+ if (!m_handler)
64+ return ;
65+
5966 // TODO: support attentionIcon/overlayIcon
6067 QPalette palette;
6168 auto textColor = DGuiApplicationHelper::instance ()->themeType () == DGuiApplicationHelper::LightType ? Qt::black : Qt::white;
0 commit comments