From 8c3d8d77cb75d6d227a92f33096bfa4dfe6bf991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Tue, 27 Feb 2018 14:06:04 +0100 Subject: [PATCH] Properly delete MainWindow --- src/CutterApplication.cpp | 33 +++++++++++++++++++++------------ src/CutterApplication.h | 12 +++--------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/CutterApplication.cpp b/src/CutterApplication.cpp index ce9fd8c6..a44ecc4e 100644 --- a/src/CutterApplication.cpp +++ b/src/CutterApplication.cpp @@ -64,9 +64,7 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc } } - MainWindow *main = new MainWindow(); - - setMainWindow(main); + mainWindow = new MainWindow(); if (args.empty()) { @@ -76,19 +74,28 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc exit(1); } - main->displayNewFileDialog(); + mainWindow->displayNewFileDialog(); } else // filename specified as positional argument { - main->openNewFile(args[0], analLevelSpecified ? analLevel : -1); + mainWindow->openNewFile(args[0], analLevelSpecified ? analLevel : -1); } } -bool CutterApplication::event(QEvent *e){ - if (e->type() == QEvent::FileOpen) { +CutterApplication::~CutterApplication() +{ + delete mainWindow; +} + +bool CutterApplication::event(QEvent *e) +{ + if (e->type() == QEvent::FileOpen) + { QFileOpenEvent *openEvent = static_cast(e); - if (openEvent) { - if (m_FileAlreadyDropped) { + if (openEvent) + { + if (m_FileAlreadyDropped) + { // we already dropped a file in macOS, let's spawn another instance // (Like the File -> Open) QString fileName = openEvent->file(); @@ -96,11 +103,13 @@ bool CutterApplication::event(QEvent *e){ process.setEnvironment(QProcess::systemEnvironment()); QStringList args = QStringList(fileName); process.startDetached(qApp->applicationFilePath(), args); - } else { + } + else + { QString fileName = openEvent->file(); m_FileAlreadyDropped = true; - m_MainWindow->closeNewFileDialog(); - m_MainWindow->openNewFile(fileName, -1); + mainWindow->closeNewFileDialog(); + mainWindow->openNewFile(fileName, -1); } } } diff --git a/src/CutterApplication.h b/src/CutterApplication.h index f7fedd22..55974c1d 100644 --- a/src/CutterApplication.h +++ b/src/CutterApplication.h @@ -10,25 +10,19 @@ class CutterApplication : public QApplication { Q_OBJECT - Q_PROPERTY(MainWindow* mainWindow READ mainWindow WRITE setMainWindow) public: CutterApplication(int &argc, char **argv); + ~CutterApplication(); - MainWindow * mainWindow() { - return m_MainWindow; - } - - void setMainWindow(MainWindow * mw) { - m_MainWindow = mw; - } + MainWindow *getMainWindow() { return mainWindow; } protected: bool event(QEvent *e); private: bool m_FileAlreadyDropped; - MainWindow *m_MainWindow; + MainWindow *mainWindow; }; #endif // CUTTERAPPLICATION_H