浏览代码

BUG: Fixed crash during exit caused by ctkMessageBox::confirmExit

The messagebox was deleted twice (first because it was created on the stack, second time when the parent window was destroyed). This caused crash on exit.

Fixed by not creating the messagebox object on the stack and deleting by setting WA_DeleteOnClose flag.
Andras Lasso 7 年之前
父节点
当前提交
f0de70029e
共有 1 个文件被更改,包括 11 次插入6 次删除
  1. 11 6
      Libs/Widgets/ctkMessageBox.cpp

+ 11 - 6
Libs/Widgets/ctkMessageBox.cpp

@@ -302,10 +302,15 @@ void ctkMessageBox::setVisible(bool visible)
 bool ctkMessageBox
 ::confirmExit(const QString& dontShowAgainKey, QWidget* parentWidget)
 {
-  ctkMessageBox dialog(parentWidget);
-  dialog.setText(tr("Are you sure you want to exit?"));
-  dialog.setIcon(QMessageBox::Question);
-  dialog.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
-  dialog.setDontShowAgainSettingsKey(dontShowAgainKey);
-  return dialog.exec() == QMessageBox::Ok;
+  ctkMessageBox* dialog = new ctkMessageBox(parentWidget);
+
+  // this will take care of destroying the window
+  // regardless the parent widget is null or non-null.
+  dialog->setAttribute(Qt::WA_DeleteOnClose);
+
+  dialog->setText(tr("Are you sure you want to exit?"));
+  dialog->setIcon(QMessageBox::Question);
+  dialog->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
+  dialog->setDontShowAgainSettingsKey(dontShowAgainKey);
+  return dialog->exec() == QMessageBox::Ok;
 }