Unregister shortcuts when closing windows that registered shortcuts

* This prevents leaking for cases where new widgets are created (and
  the small chance a widget pointer could be re-used and cause serious
  problems), and multiple-registration errors for global shortcuts.
This commit is contained in:
baldurk
2017-11-22 16:07:14 +00:00
parent cadc0f3855
commit 38acc56084
5 changed files with 68 additions and 1 deletions
+31
View File
@@ -249,6 +249,12 @@ MainWindow::MainWindow(ICaptureContext &ctx) : QMainWindow(NULL), ui(new Ui::Mai
MainWindow::~MainWindow()
{
// explicitly delete our children here, so that the MainWindow is still alive while they are
// closing.
setUpdatesEnabled(false);
qDeleteAll(findChildren<QWidget *>(QString(), Qt::FindDirectChildrenOnly));
m_RemoteProbeSemaphore.acquire();
m_RemoteProbe->wait();
m_RemoteProbe->deleteLater();
@@ -1376,6 +1382,31 @@ void MainWindow::RegisterShortcut(const QString &shortcut, QWidget *widget, Shor
}
}
void MainWindow::UnregisterShortcut(const QString &shortcut, QWidget *widget)
{
if(widget)
{
if(shortcut.isEmpty())
{
// if no shortcut is specified, remove all shortcuts for this widget
for(QMap<QWidget *, ShortcutCallback> &sh : m_WidgetShortcutCallbacks)
sh.remove(widget);
}
else
{
QKeySequence ks = QKeySequence::fromString(shortcut);
m_WidgetShortcutCallbacks[ks].remove(widget);
}
}
else
{
QKeySequence ks = QKeySequence::fromString(shortcut);
m_GlobalShortcutCallbacks.remove(ks);
}
}
bool MainWindow::eventFilter(QObject *watched, QEvent *event)
{
if(event->type() == QEvent::ShortcutOverride)