┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/disabledactionnotifier.cpp
diff options
context:
space:
mode:
authorJoshua Goins <[email protected]>2024-04-11 11:20:02 +0000
committerJin Liu <[email protected]>2024-04-11 11:20:02 +0000
commit39ce7268627ca3ac28b24a3ea4ae266459833cb7 (patch)
tree766b75aeb5b65e92a0117c25a9dec9132d4d8855 /src/disabledactionnotifier.cpp
parent1ef57e953325eb728aa27b812fafeecb61586f5e (diff)
DisabledActionNotifier: Prevent null dereferences
This prevents a crash on startup where it tries to delete a null QShortcut because it didn't check if the QShortcut actually exists in the QHash. BUG: 485089
Diffstat (limited to 'src/disabledactionnotifier.cpp')
-rw-r--r--src/disabledactionnotifier.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/disabledactionnotifier.cpp b/src/disabledactionnotifier.cpp
index 844e66228..0b83a9664 100644
--- a/src/disabledactionnotifier.cpp
+++ b/src/disabledactionnotifier.cpp
@@ -18,17 +18,22 @@ void DisabledActionNotifier::setDisabledReason(QAction *action, QStringView reas
}
if (m_shortcuts.contains(action)) {
- m_shortcuts.take(action)->deleteLater();
+ clearDisabledReason(action);
}
QShortcut *shortcut = new QShortcut(action->shortcut(), parent());
m_shortcuts.insert(action, shortcut);
- connect(action, &QAction::enabledChanged, this, [this, action](bool enabled) {
- if (enabled) {
- m_shortcuts.take(action)->deleteLater();
- }
- });
+ connect(
+ action,
+ &QAction::enabledChanged,
+ this,
+ [this, action](bool enabled) {
+ if (enabled && m_shortcuts.contains(action)) {
+ m_shortcuts.take(action)->deleteLater();
+ }
+ },
+ Qt::SingleShotConnection);
// Don't capture QStringView, as it may reference a temporary QString
QString reasonString = reason.toString();
@@ -43,6 +48,7 @@ void DisabledActionNotifier::clearDisabledReason(QAction *action)
return;
}
+ action->disconnect(this);
if (m_shortcuts.contains(action)) {
m_shortcuts.take(action)->deleteLater();
}