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
This commit is contained in:
kalaposfos13 2024-11-21 20:31:23 +01:00
parent 216a5dcbc2
commit 195ef4c02f
3 changed files with 14 additions and 3 deletions

View File

@ -144,7 +144,7 @@ bool isHelpOpen = false;
HelpDialog* helpDialog; HelpDialog* helpDialog;
void EditorDialog::onHelpClicked() { void EditorDialog::onHelpClicked() {
if (!isHelpOpen) { if (!isHelpOpen) {
helpDialog = new HelpDialog(this); helpDialog = new HelpDialog(&isHelpOpen, this);
helpDialog->setWindowTitle("Help"); helpDialog->setWindowTitle("Help");
helpDialog->setAttribute(Qt::WA_DeleteOnClose); // Clean up on close helpDialog->setAttribute(Qt::WA_DeleteOnClose); // Clean up on close
// Get the position and size of the Config window // Get the position and size of the Config window

View File

@ -58,7 +58,13 @@ ExpandableSection::ExpandableSection(const QString& title, const QString& conten
layout->setContentsMargins(0, 0, 0, 0); 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 // Main layout for the help dialog
QVBoxLayout* mainLayout = new QVBoxLayout(this); QVBoxLayout* mainLayout = new QVBoxLayout(this);

View File

@ -33,9 +33,14 @@ private:
class HelpDialog : public QDialog { class HelpDialog : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit HelpDialog(QWidget* parent = nullptr); explicit HelpDialog(bool* open_flag = nullptr, QWidget* parent = nullptr);
protected:
void closeEvent(QCloseEvent* event) override;
private: private:
bool* help_open_ptr;
QString quickstart() { QString quickstart() {
return return
R"(The keyboard remapping backend, GUI and documentation have been written by kalaposfos R"(The keyboard remapping backend, GUI and documentation have been written by kalaposfos