From 94cb6ce1c562d7be0bc71e165f73c8ec5cd66353 Mon Sep 17 00:00:00 2001 From: "anthony.bilinski" Date: Thu, 21 Sep 2017 11:25:27 -0700 Subject: [PATCH] fix(settings): Delete dynamically allocated members on destruction Fixes #4670 --- src/widget/form/settingswidget.cpp | 36 ++++++++++++++++-------------- src/widget/form/settingswidget.h | 6 +++-- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/widget/form/settingswidget.cpp b/src/widget/form/settingswidget.cpp index c55a56544..99487cbe4 100644 --- a/src/widget/form/settingswidget.cpp +++ b/src/widget/form/settingswidget.cpp @@ -19,10 +19,6 @@ #include "settingswidget.h" -#include -#include -#include - #include "src/video/camerasource.h" #include "src/widget/contentlayout.h" #include "src/widget/form/settings/aboutform.h" @@ -34,6 +30,12 @@ #include "src/widget/translator.h" #include "src/widget/widget.h" +#include +#include +#include + +#include + SettingsWidget::SettingsWidget(QWidget* parent) : QWidget(parent, Qt::Window) { @@ -41,22 +43,22 @@ SettingsWidget::SettingsWidget(QWidget* parent) QVBoxLayout* bodyLayout = new QVBoxLayout(); - settingsWidgets = new QTabWidget(this); + settingsWidgets = std::unique_ptr(new QTabWidget(this)); settingsWidgets->setTabPosition(QTabWidget::North); - bodyLayout->addWidget(settingsWidgets); + bodyLayout->addWidget(settingsWidgets.get()); - GeneralForm* gfrm = new GeneralForm(this); - UserInterfaceForm* uifrm = new UserInterfaceForm(this); - PrivacyForm* pfrm = new PrivacyForm(); - AVForm* avfrm = new AVForm(); - AdvancedForm* expfrm = new AdvancedForm(); - AboutForm* abtfrm = new AboutForm(); + std::unique_ptr gfrm(new GeneralForm(this)); + std::unique_ptr uifrm(new UserInterfaceForm(this)); + std::unique_ptr pfrm(new PrivacyForm()); + std::unique_ptr avfrm(new AVForm()); + std::unique_ptr expfrm(new AdvancedForm()); + std::unique_ptr abtfrm(new AboutForm()); - cfgForms = {{gfrm, uifrm, pfrm, avfrm, expfrm, abtfrm}}; - for (GenericForm* cfgForm : cfgForms) - settingsWidgets->addTab(cfgForm, cfgForm->getFormIcon(), cfgForm->getFormName()); + cfgForms = {{std::move(gfrm), std::move(uifrm), std::move(pfrm), std::move(avfrm), std::move(expfrm), std::move(abtfrm)}}; + for (auto& cfgForm : cfgForms) + settingsWidgets->addTab(cfgForm.get(), cfgForm->getFormIcon(), cfgForm->getFormName()); - connect(settingsWidgets, &QTabWidget::currentChanged, this, &SettingsWidget::onTabChanged); + connect(settingsWidgets.get(), &QTabWidget::currentChanged, this, &SettingsWidget::onTabChanged); Translator::registerHandler(std::bind(&SettingsWidget::retranslateUi, this), this); } @@ -88,7 +90,7 @@ bool SettingsWidget::isShown() const void SettingsWidget::show(ContentLayout* contentLayout) { - contentLayout->mainContent->layout()->addWidget(settingsWidgets); + contentLayout->mainContent->layout()->addWidget(settingsWidgets.get()); settingsWidgets->show(); onTabChanged(settingsWidgets->currentIndex()); } diff --git a/src/widget/form/settingswidget.h b/src/widget/form/settingswidget.h index 5bd5cbcbf..f2166065d 100644 --- a/src/widget/form/settingswidget.h +++ b/src/widget/form/settingswidget.h @@ -23,7 +23,9 @@ #include #include #include + #include +#include class Camera; class GenericForm; @@ -54,8 +56,8 @@ private: void retranslateUi(); private: - QTabWidget* settingsWidgets; - std::array cfgForms; + std::unique_ptr settingsWidgets; + std::array, 6> cfgForms; int currentIndex; };