# HG changeset patch # User Yuya Nishihara # Date 1579270258 -32400 # Fri Jan 17 23:10:58 2020 +0900 # Node ID 5856113283730ea67c4efc4c02222256c845fc54 # Parent 1b47d15757f00324a33c2748ac4ba42cd99f8669 manage ui instance by unique_ptr diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) # QtCreator supports the following variables for Android, which are identical to qmake Android variables. diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -4,16 +4,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) - , ui(new Ui::MainWindow) + , ui_(std::make_unique()) { - ui->setupUi(this); + ui_->setupUi(this); auto *model = new QStringListModel({"Foo", "Bar", "Baz"}, this); - ui->treeView->setModel(model); + ui_->treeView->setModel(model); } -MainWindow::~MainWindow() -{ - delete ui; -} +MainWindow::~MainWindow() = default; diff --git a/mainwindow.h b/mainwindow.h --- a/mainwindow.h +++ b/mainwindow.h @@ -2,6 +2,7 @@ #define MAINWINDOW_H #include +#include QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -13,9 +14,9 @@ public: MainWindow(QWidget *parent = nullptr); - ~MainWindow(); + ~MainWindow() override; private: - Ui::MainWindow *ui; + std::unique_ptr ui_; }; #endif // MAINWINDOW_H