}
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();
return;
}
+ action->disconnect(this);
if (m_shortcuts.contains(action)) {
m_shortcuts.take(action)->deleteLater();
}