diff --git a/src/kiwixmessagebox.cpp b/src/kiwixmessagebox.cpp index e614d99e9..56dad5a23 100644 --- a/src/kiwixmessagebox.cpp +++ b/src/kiwixmessagebox.cpp @@ -10,6 +10,7 @@ KiwixMessageBox::KiwixMessageBox(QString confirmTitle, QString confirmText, bool { ui->setupUi(this); setWindowFlag(Qt::FramelessWindowHint, true); + setAttribute(Qt::WA_DeleteOnClose); setStyleSheet(KiwixApp::instance()->parseStyleFromFile(":/css/messageBox.css")); connect(ui->yesButton, &QPushButton::clicked, [=]() { emit yesClicked(); @@ -24,10 +25,12 @@ KiwixMessageBox::KiwixMessageBox(QString confirmTitle, QString confirmText, bool connect(ui->okButton, &QPushButton::clicked, [=]() { emit okClicked(); m_result = OkClicked; + accept(); }); connect(ui->closeButton, &QPushButton::clicked, [=]() { this->close(); m_result = CloseClicked; + reject(); }); ui->confirmText->setText(confirmText); ui->confirmTitle->setText(confirmTitle); @@ -50,15 +53,11 @@ KiwixMessageBox::~KiwixMessageBox() void showInfoBox(QString title, QString text, QWidget *parent) { KiwixMessageBox *dialog = new KiwixMessageBox(title, text, true, parent); - dialog->show(); - QObject::connect(dialog, &KiwixMessageBox::okClicked, [=]() { - dialog->deleteLater(); - }); + dialog->execDialog(); } KiwixMessageBox::Result showKiwixMessageBox(QString title, QString text, QWidget *parent, QString leftTitle, QString rightTitle) { KiwixMessageBox *dialog = new KiwixMessageBox(title, text, false, parent, leftTitle, rightTitle); - dialog->setAttribute(Qt::WA_DeleteOnClose); return dialog->execDialog(); } diff --git a/src/kiwixmessagebox.h b/src/kiwixmessagebox.h index 7bf2f9aa9..9edb2bb50 100644 --- a/src/kiwixmessagebox.h +++ b/src/kiwixmessagebox.h @@ -45,14 +45,10 @@ void showConfirmBox(QString title, QString text, QWidget *parent, YesAction yesAction) { KiwixMessageBox *dialog = new KiwixMessageBox(title, text, false, parent); - dialog->show(); - QObject::connect(dialog, &KiwixMessageBox::yesClicked, [=]() { + auto res = dialog->execDialog(); + if (res == KiwixMessageBox::Result::YesClicked) { yesAction(); - dialog->deleteLater(); - }); - QObject::connect(dialog, &KiwixMessageBox::noClicked, [=]() { - dialog->deleteLater(); - }); + } } #endif // KIWIXMESSAGEBOX_H