From 6e24762a6cab33abd34c3d28f47119b0ac25e7e6 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 29 Sep 2018 21:41:37 +0200 Subject: [PATCH] Cleanup: Don't leak DiveLogImportDialog objects The non-modal DiveLogImportDialog was only implicitly deleted when the MainWindow was destroyed. Instead hook into the accept() and reject() functions and schedule for deletion with deleteLater(). Quite the horrible proposition, but in line with Qt's object model. Consider making the dialog modal instead. There seems to be no upside for this being modal. Signed-off-by: Berthold Stoeger --- desktop-widgets/divelogimportdialog.cpp | 16 ++++++++++++++++ desktop-widgets/divelogimportdialog.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/desktop-widgets/divelogimportdialog.cpp b/desktop-widgets/divelogimportdialog.cpp index 4d092bb8c..2068c3916 100644 --- a/desktop-widgets/divelogimportdialog.cpp +++ b/desktop-widgets/divelogimportdialog.cpp @@ -951,6 +951,22 @@ void DiveLogImportDialog::on_buttonBox_accepted() MainWindow::instance()->refreshDisplay(); } +// Since this is a non-modal dialog, the caller can't delete it at the call-site. +// Therefore, hook into the accept() and reject() functions and schedule the object +// for deletion with deleteLater(). Horrible, but absolutely the "Qt-way". +// TODO: Think about making the dialog modal. +void DiveLogImportDialog::accept() +{ + QDialog::accept(); + deleteLater(); +} + +void DiveLogImportDialog::reject() +{ + QDialog::reject(); + deleteLater(); +} + TagDragDelegate::TagDragDelegate(QObject *parent) : QStyledItemDelegate(parent) { } diff --git a/desktop-widgets/divelogimportdialog.h b/desktop-widgets/divelogimportdialog.h index f01ec282d..a6f2a8868 100644 --- a/desktop-widgets/divelogimportdialog.h +++ b/desktop-widgets/divelogimportdialog.h @@ -89,6 +89,8 @@ slots: void loadFileContents(int value, enum whatChanged triggeredBy); int setup_csv_params(QStringList r, char **params, int pnr); int parseTxtHeader(QString fileName, char **params, int pnr); + void accept() override; + void reject() override; private: bool selector;