Skip to content

Commit 8f605e5

Browse files
committed
fix: 修复 Toast 频繁显示的崩溃;
1 parent 84486c3 commit 8f605e5

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/control/toast.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,24 @@ void Toast::toast(QWidget *parent, const QPixmap &icon,
7474

7575
if (_toast) {
7676
_toast->hide();
77-
_toast->destroy();
7877
_toast->deleteLater();
7978
}
8079

8180
static QRegularExpression regex(QStringLiteral("\r\n|\n"));
8281
auto str = strContent;
8382
str.remove(regex);
8483
_toast = new Toast(str, icon, nToastInterval, parent);
85-
connect(_toast, &Toast::destroyed, _toast, [&] {
86-
_toast->parent()->removeEventFilter(_toast);
87-
_toast = nullptr;
88-
});
8984
parent->installEventFilter(_toast);
9085
qApp->installEventFilter(_toast);
9186
_toast->show();
9287
}
9388

94-
Toast::~Toast() {}
89+
Toast::~Toast() {
90+
parent()->removeEventFilter(this);
91+
if (_toast == this) {
92+
_toast = nullptr;
93+
}
94+
}
9595

9696
QSize Toast::calculateTextSize() {
9797
QFontMetrics metrice(displayFont());

0 commit comments

Comments
 (0)