From 195ef4c02f56d866c8c639928ee9fca6aad5ca1e Mon Sep 17 00:00:00 2001 From: kalaposfos13 <153381648+kalaposfos13@users.noreply.github.com> Date: Thu, 21 Nov 2024 20:31:23 +0100 Subject: [PATCH] Fix crash if the Help dialog was opened a second time If it's closed with the top right close button instead of clicking the Help button again, a required flag wasn't reset, making the next click on Help try to close a nonexistent window and segfault --- src/qt_gui/kbm_config_dialog.cpp | 2 +- src/qt_gui/kbm_help_dialog.cpp | 8 +++++++- src/qt_gui/kbm_help_dialog.h | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/qt_gui/kbm_config_dialog.cpp b/src/qt_gui/kbm_config_dialog.cpp index c808629d2..6931c336c 100644 --- a/src/qt_gui/kbm_config_dialog.cpp +++ b/src/qt_gui/kbm_config_dialog.cpp @@ -144,7 +144,7 @@ bool isHelpOpen = false; HelpDialog* helpDialog; void EditorDialog::onHelpClicked() { if (!isHelpOpen) { - helpDialog = new HelpDialog(this); + helpDialog = new HelpDialog(&isHelpOpen, this); helpDialog->setWindowTitle("Help"); helpDialog->setAttribute(Qt::WA_DeleteOnClose); // Clean up on close // Get the position and size of the Config window diff --git a/src/qt_gui/kbm_help_dialog.cpp b/src/qt_gui/kbm_help_dialog.cpp index feb24ce5d..6b27b5e9c 100644 --- a/src/qt_gui/kbm_help_dialog.cpp +++ b/src/qt_gui/kbm_help_dialog.cpp @@ -58,7 +58,13 @@ ExpandableSection::ExpandableSection(const QString& title, const QString& conten layout->setContentsMargins(0, 0, 0, 0); } -HelpDialog::HelpDialog(QWidget* parent) : QDialog(parent) { +void HelpDialog::closeEvent(QCloseEvent* event) { + *help_open_ptr = false; + close(); +} + +HelpDialog::HelpDialog(bool* open_flag, QWidget* parent) : QDialog(parent) { + help_open_ptr = open_flag; // Main layout for the help dialog QVBoxLayout* mainLayout = new QVBoxLayout(this); diff --git a/src/qt_gui/kbm_help_dialog.h b/src/qt_gui/kbm_help_dialog.h index d9270e9bf..4348f9a33 100644 --- a/src/qt_gui/kbm_help_dialog.h +++ b/src/qt_gui/kbm_help_dialog.h @@ -33,9 +33,14 @@ private: class HelpDialog : public QDialog { Q_OBJECT public: - explicit HelpDialog(QWidget* parent = nullptr); + explicit HelpDialog(bool* open_flag = nullptr, QWidget* parent = nullptr); + +protected: + void closeEvent(QCloseEvent* event) override; private: + bool* help_open_ptr; + QString quickstart() { return R"(The keyboard remapping backend, GUI and documentation have been written by kalaposfos