mirror of https://github.com/mgba-emu/mgba.git
Qt: Fix Action leak
This commit is contained in:
parent
ffacbcfeea
commit
45387aa663
|
@ -93,7 +93,13 @@ void ActionMapper::rebuildMenu(const QString& menu, QMenu* qmenu, QWidget* conte
|
|||
qaction->setMenuRole(QAction::QuitRole);
|
||||
break;
|
||||
}
|
||||
QObject::connect(qaction, &QAction::triggered, [qaction, action](bool enabled) {
|
||||
|
||||
std::weak_ptr<Action> weakAction(action);
|
||||
QObject::connect(qaction, &QAction::triggered, [qaction, weakAction](bool enabled) {
|
||||
if (weakAction.expired()) {
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<Action> action(weakAction.lock());
|
||||
if (qaction->isCheckable()) {
|
||||
action->trigger(enabled);
|
||||
} else {
|
||||
|
@ -101,7 +107,8 @@ void ActionMapper::rebuildMenu(const QString& menu, QMenu* qmenu, QWidget* conte
|
|||
}
|
||||
});
|
||||
QObject::connect(action.get(), &Action::enabled, qaction, &QAction::setEnabled);
|
||||
QObject::connect(action.get(), &Action::activated, [qaction, action](bool active) {
|
||||
QObject::connect(action.get(), &Action::activated, [qaction, weakAction](bool active) {
|
||||
std::shared_ptr<Action> action(weakAction.lock());
|
||||
if (qaction->isCheckable()) {
|
||||
qaction->setChecked(active);
|
||||
} else if (active) {
|
||||
|
|
|
@ -49,7 +49,12 @@ std::shared_ptr<Action> ConfigOption::addValue(const QString& text, const QVaria
|
|||
action = std::make_shared<Action>(function, name, text, this);
|
||||
}
|
||||
action->setExclusive();
|
||||
QObject::connect(action.get(), &QObject::destroyed, this, [this, action, value]() {
|
||||
std::weak_ptr<Action> weakAction(action);
|
||||
QObject::connect(action.get(), &QObject::destroyed, this, [this, weakAction, value]() {
|
||||
if (weakAction.expired()) {
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<Action> action(weakAction.lock());
|
||||
m_actions.removeAll(std::make_pair(action, value));
|
||||
});
|
||||
m_actions.append(std::make_pair(action, value));
|
||||
|
@ -71,7 +76,12 @@ std::shared_ptr<Action> ConfigOption::addBoolean(const QString& text, ActionMapp
|
|||
action = std::make_shared<Action>(function, m_name, text, this);
|
||||
}
|
||||
|
||||
QObject::connect(action.get(), &QObject::destroyed, this, [this, action]() {
|
||||
std::weak_ptr<Action> weakAction(action);
|
||||
QObject::connect(action.get(), &QObject::destroyed, this, [this, weakAction]() {
|
||||
if (weakAction.expired()) {
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<Action> action(weakAction.lock());
|
||||
m_actions.removeAll(std::make_pair(action, QVariant(1)));
|
||||
});
|
||||
m_actions.append(std::make_pair(action, QVariant(1)));
|
||||
|
|
Loading…
Reference in New Issue