summaryrefslogtreecommitdiffhomepage
path: root/gui
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-02-23 08:00:46 +0100
committerStanislaw Halik <sthalik@misaki.pl>2017-02-23 08:54:35 +0100
commit1e91bdd402b5d3ae1f46111bd2f1fc670300433c (patch)
treef2a9c295836ded02ca8eff311b2466c59b810ad1 /gui
parent3f1eb355678d37abc2076e876a933c7b037856a8 (diff)
gui/options-dialog: prevent heisenbugs (?)
It's likely that there's some memory handling bug when stack-allocating Qt widgets and other components. Use QObject::deleteLater. Will check with Valgrind later.
Diffstat (limited to 'gui')
-rw-r--r--gui/options-dialog.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/gui/options-dialog.cpp b/gui/options-dialog.cpp
index cedb1e52..98953086 100644
--- a/gui/options-dialog.cpp
+++ b/gui/options-dialog.cpp
@@ -150,42 +150,44 @@ void OptionsDialog::bind_key(key_opts& kopts, QLabel* label)
kopts.button = -1;
kopts.guid = "";
kopts.keycode = "";
- QDialog d;
- QHBoxLayout l;
- l.setMargin(0);
- KeyboardListener k;
- l.addWidget(&k);
- d.setLayout(&l);
- d.setFixedSize(QSize(500, 300));
- d.setWindowFlags(Qt::Dialog);
- setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | windowFlags());
- d.setWindowModality(Qt::ApplicationModal);
- connect(&k,
+ auto d = new QDialog(this, Qt::MSWindowsFixedSizeDialogHint);
+ auto l = new QHBoxLayout;
+ l->setMargin(0);
+ auto k = new KeyboardListener;
+ l->addWidget(k);
+ d->setLayout(l);
+ d->setFixedSize(QSize(500, 300));
+ d->setWindowModality(Qt::ApplicationModal);
+
+ d->deleteLater();
+ l->deleteLater();
+ k->deleteLater();
+
+ connect(k,
&KeyboardListener::key_pressed,
- &d,
- [&](QKeySequence s) -> void
+ d,
+ [&](QKeySequence s)
{
kopts.keycode = s.toString(QKeySequence::PortableText);
kopts.guid = "";
kopts.button = -1;
- d.close();
+ d->close();
});
- connect(&k, &KeyboardListener::joystick_button_pressed,
- &d,
- [&](QString guid, int idx, bool held) -> void
+ connect(k, &KeyboardListener::joystick_button_pressed,
+ d,
+ [&](QString guid, int idx, bool held)
{
if (!held)
{
kopts.guid = guid;
kopts.keycode = "";
kopts.button = idx;
- d.close();
+ d->close();
}
});
- connect(main.b.get(), &options::detail::bundle::reloading, &d, &QDialog::close);
+ connect(main.b.get(), &options::detail::bundle::reloading, d, &QDialog::close);
pause_keybindings(true);
- d.show();
- d.exec();
+ d->exec();
pause_keybindings(false);
label->setText(kopts_to_string(kopts));
}