summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-04-13 10:54:06 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-14 03:16:48 +1200
commit88ed5bf05054a3a4b2313cec81e6756279e6bdb1 (patch)
tree6cb2fe00c1c393645e7aac99387f9f807190d376
parent17e7cc048feee5f5b46a4ea3932e2e6500ec5e58 (diff)
downloadsubsurface-88ed5bf05054a3a4b2313cec81e6756279e6bdb1.tar.gz
Desktop: destroy maintab before destructing mainwindow
Apparently, in some Qt-versions the destructor of the base class calls hide on child-objects (according to Qt's object hierarchy). This is obviously called after the derived class has been destructed. In a concrete case, the base class of the destructed MainWindow would hide the TabDiveSite object. That would reset the filtering if a dive site was selected, which would indirectly access the MainWindow, which is already partially destroyed. Therefore, destroy the MainTab before destroying the MainWindow. Do this by keeping it as a std::unique_ptr subobject. Thus, it will be destroyed before the MainWindow and remove itself from Qt's object hierarchy. Reported-by: Dirk Hohndel <dirk@hohndel.org> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--desktop-widgets/mainwindow.cpp14
-rw-r--r--desktop-widgets/mainwindow.h3
2 files changed, 9 insertions, 8 deletions
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index e1933a472..c509a7607 100644
--- a/desktop-widgets/mainwindow.cpp
+++ b/desktop-widgets/mainwindow.cpp
@@ -133,7 +133,7 @@ MainWindow::MainWindow() : QMainWindow(),
// widgets will change on the mainwindow.
// for the "default" mode
- mainTab = new MainTab(this);
+ mainTab.reset(new MainTab);
diveList = new DiveListView(this);
graphics = new ProfileWidget2(this);
MapWidget *mapWidget = MapWidget::instance();
@@ -177,12 +177,12 @@ MainWindow::MainWindow() : QMainWindow(),
enabledList.push_back(enabled);
disabledList.push_back(disabled);
- registerApplicationState("Default", mainTab, profileContainer, diveList, mapWidget );
- registerApplicationState("EditDive", mainTab, profileContainer, diveList, mapWidget );
+ registerApplicationState("Default", mainTab.get(), profileContainer, diveList, mapWidget );
+ registerApplicationState("EditDive", mainTab.get(), profileContainer, diveList, mapWidget );
registerApplicationState("PlanDive", divePlannerWidget, profileContainer, divePlannerSettingsWidget, plannerDetails );
registerApplicationState("EditPlannedDive", divePlannerWidget, profileContainer, diveList, mapWidget );
registerApplicationState("EditDiveSite", diveSiteEdit, profileContainer, diveList, mapWidget);
- registerApplicationState("FilterDive", mainTab, profileContainer, diveList, &filterWidget2);
+ registerApplicationState("FilterDive", mainTab.get(), profileContainer, diveList, &filterWidget2);
setStateProperties("Default", enabledList, enabledList, enabledList, enabledList);
setStateProperties("EditDive", enabledList, enabledList, enabledList, enabledList);
@@ -200,7 +200,7 @@ MainWindow::MainWindow() : QMainWindow(),
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(readSettings()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), diveList, SLOT(update()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), diveList, SLOT(reloadHeaderActions()));
- connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), mainTab, SLOT(updateDiveInfo()));
+ connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), mainTab.get(), SLOT(updateDiveInfo()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), divePlannerWidget, SLOT(settingsChanged()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), divePlannerSettingsWidget, SLOT(settingsChanged()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), TankInfoModel::instance(), SLOT(update()));
@@ -215,7 +215,7 @@ MainWindow::MainWindow() : QMainWindow(),
connect(DivePlannerPointsModel::instance(), SIGNAL(planCanceled()), this, SLOT(planCanceled()));
connect(DivePlannerPointsModel::instance(), SIGNAL(variationsComputed(QString)), this, SLOT(updateVariations(QString)));
connect(plannerDetails->printPlan(), SIGNAL(pressed()), divePlannerWidget, SLOT(printDecoPlan()));
- connect(mainTab, &MainTab::diveSiteChanged, mapWidget, &MapWidget::centerOnSelectedDiveSite);
+ connect(mainTab.get(), &MainTab::diveSiteChanged, mapWidget, &MapWidget::centerOnSelectedDiveSite);
connect(this, &MainWindow::showError, ui.mainErrorMessage, &NotificationWidget::showError, Qt::AutoConnection);
connect(&windowTitleUpdate, &WindowTitleUpdate::updateTitle, this, &MainWindow::setAutomaticTitle);
@@ -327,7 +327,7 @@ MainWindow::MainWindow() : QMainWindow(),
connect(graphics, &ProfileWidget2::enableShortcuts, this, &MainWindow::enableShortcuts);
connect(graphics, &ProfileWidget2::refreshDisplay, this, &MainWindow::refreshDisplay);
connect(graphics, &ProfileWidget2::editCurrentDive, this, &MainWindow::editCurrentDive);
- connect(graphics, &ProfileWidget2::updateDiveInfo, mainTab, &MainTab::updateDiveInfo);
+ connect(graphics, &ProfileWidget2::updateDiveInfo, mainTab.get(), &MainTab::updateDiveInfo);
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), graphics, SLOT(settingsChanged()));
diff --git a/desktop-widgets/mainwindow.h b/desktop-widgets/mainwindow.h
index efac8610e..252a95b98 100644
--- a/desktop-widgets/mainwindow.h
+++ b/desktop-widgets/mainwindow.h
@@ -13,6 +13,7 @@
#include <QUrl>
#include <QUuid>
#include <QProgressDialog>
+#include <memory>
#include "ui_mainwindow.h"
#include "ui_plannerDetails.h"
@@ -84,7 +85,7 @@ public:
void exitEditState();
void editDiveSite(dive_site *ds);
- MainTab *mainTab;
+ std::unique_ptr<MainTab> mainTab;
PlannerDetails *plannerDetails;
PlannerSettingsWidget *divePlannerSettingsWidget;
ProfileWidget2 *graphics;