From 7343fe4cc6e364dd3be8f2af4efd9f3a2d748c58 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 29 Sep 2019 13:21:12 +0200 Subject: [PATCH] Cleanup: Implicitly free QApplication Instead of deleting the Application explicitly in exit_ui(), use a unique_ptr to have the instance automatically freed. This is the pattern given in the Qt-docs: https://doc.qt.io/qt-5/qapplication.html Signed-off-by: Berthold Stoeger --- subsurface-desktop-main.cpp | 2 +- subsurface-helper.cpp | 1 - subsurface-mobile-main.cpp | 3 +-- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/subsurface-desktop-main.cpp b/subsurface-desktop-main.cpp index 60bf81c74..981a62a04 100644 --- a/subsurface-desktop-main.cpp +++ b/subsurface-desktop-main.cpp @@ -43,7 +43,7 @@ int main(int argc, char **argv) int i; bool no_filenames = true; QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); - new QApplication(argc, argv); + std::unique_ptr app(new QApplication(argc, argv)); QStringList files; QStringList importedFiles; QStringList arguments = QCoreApplication::arguments(); diff --git a/subsurface-helper.cpp b/subsurface-helper.cpp index c389e2099..9ce1a615a 100644 --- a/subsurface-helper.cpp +++ b/subsurface-helper.cpp @@ -56,7 +56,6 @@ void exit_ui() #ifndef SUBSURFACE_MOBILE delete MainWindow::instance(); #endif // SUBSURFACE_MOBILE - delete qApp; free((void *)existing_filename); } diff --git a/subsurface-mobile-main.cpp b/subsurface-mobile-main.cpp index 64c941fc7..b75c63406 100644 --- a/subsurface-mobile-main.cpp +++ b/subsurface-mobile-main.cpp @@ -53,7 +53,6 @@ void log_stp(const char *ident, QString *buf) } #endif // ENABLE_STARTUP_TIMING - int main(int argc, char **argv) { LOG_STP("main starting"); @@ -63,7 +62,7 @@ int main(int argc, char **argv) QLoggingCategory::setFilterRules(QStringLiteral("qt.bluetooth* = true")); // Start application - new QApplication(argc, argv); + std::unique_ptr app(new QApplication(argc, argv)); LOG_STP("main Qt started"); // and get comand line arguments