diff --git a/snapshot.cpp b/snapshot.cpp --- a/snapshot.cpp +++ b/snapshot.cpp @@ -15,6 +15,14 @@ SnapShot::SnapShot(QMainWindow* parent, connect(&_menuAction, &QAction::triggered, this, &SnapShot::show); } +SnapShot::~SnapShot() +{ + if (view != NULL) + { + delete view; + } +} + QAction* SnapShot::menuAction() { return &_menuAction; @@ -26,6 +34,7 @@ void SnapShot::show() { qDebug() << "view == NULL"; view = new SnapShotView(mainWindow, this); + connect(view, &SnapShotView::closed, this, &SnapShot::viewClosed); } view->show(); } @@ -34,3 +43,9 @@ void SnapShot::hide() { } + +void SnapShot::viewClosed() +{ + delete view; + view = NULL; +} diff --git a/snapshot.h b/snapshot.h --- a/snapshot.h +++ b/snapshot.h @@ -14,6 +14,7 @@ class SnapShot : public QObject public: SnapShot(QMainWindow* parent, QString name); + ~SnapShot(); // QString _name; QVector> data; @@ -27,6 +28,9 @@ private: QAction _menuAction; QMainWindow* mainWindow; SnapShotView* view; + +private slots: + void viewClosed(); }; #endif /* SNAPSHOT_H */ diff --git a/snapshotview.cpp b/snapshotview.cpp --- a/snapshotview.cpp +++ b/snapshotview.cpp @@ -29,3 +29,8 @@ SnapShotView::~SnapShotView() } delete ui; } + +void SnapShotView::closeEvent(QCloseEvent *event) +{ + emit closed(); +} diff --git a/snapshotview.h b/snapshotview.h --- a/snapshotview.h +++ b/snapshotview.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "plot.h" #include "snapshot.h" @@ -21,11 +22,15 @@ public: explicit SnapShotView(QWidget *parent, SnapShot* snapShot); ~SnapShotView(); +signals: + void closed(); + private: Ui::SnapShotView *ui; QList curves; SnapShot* _snapShot; + void closeEvent(QCloseEvent *event); }; #endif // SNAPSHOTVIEW_H