From 3c2b0322c0771c0fa8aee7fc9e4ecccf66a9d0a5 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Fri, 3 Nov 2023 07:54:52 +0100 Subject: [PATCH] mupp: got rid of some left over raw pointers by replacing them through smartpointers. --- src/musredit_qt5/mupp/mupp.cpp | 21 +++++++++++++++------ src/musredit_qt6/mupp/mupp.cpp | 21 +++++++++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/musredit_qt5/mupp/mupp.cpp b/src/musredit_qt5/mupp/mupp.cpp index a36c52c5..336680bb 100644 --- a/src/musredit_qt5/mupp/mupp.cpp +++ b/src/musredit_qt5/mupp/mupp.cpp @@ -598,17 +598,26 @@ int main(int argc, char *argv[]) } QCoreApplication *app = createApplication(argc, argv, guiFlag); + std::unique_ptr gui; + std::unique_ptr mupp_script; if (qobject_cast(app)) { // GUI - PmuppGui *gui = new PmuppGui(fln); + gui = std::make_unique(fln); + if (gui == nullptr) { + std::cerr << std::endl; + std::cerr << "*********" << std::endl; + std::cerr << "**ERROR** couldn't invoke mupp gui..." << std::endl; + std::cerr << "*********" << std::endl; + return -1; + } gui->setWindowTitle( "muSR Parameter Plotter" ); gui->resize( 800, 500 ); gui->show(); app->connect( app, SIGNAL( lastWindowClosed() ), app, SLOT( quit() ) ); - app->connect( app, SIGNAL( aboutToQuit() ), gui, SLOT( aboutToQuit() ) ); + app->connect( app, SIGNAL( aboutToQuit() ), gui.get(), SLOT( aboutToQuit() ) ); } else { // scripting - PmuppScript *mupp_script = new PmuppScript(script); - if (mupp_script == 0) { + mupp_script = std::make_unique(script); + if (mupp_script == nullptr) { std::cerr << std::endl; std::cerr << "*********" << std::endl; std::cerr << "**ERROR** couldn't invoke script class..." << std::endl; @@ -617,10 +626,10 @@ int main(int argc, char *argv[]) } // This will cause the application to exit when the task signals finished. - QObject::connect( mupp_script, SIGNAL( finished() ), app, SLOT( quit() ) ); + QObject::connect( mupp_script.get(), SIGNAL( finished() ), app, SLOT( quit() ) ); // This will run the task from the application event loop. - QTimer::singleShot(0, mupp_script, SLOT( executeScript() ) ); + QTimer::singleShot(0, mupp_script.get(), SLOT( executeScript() ) ); } return app->exec(); diff --git a/src/musredit_qt6/mupp/mupp.cpp b/src/musredit_qt6/mupp/mupp.cpp index 2d81d594..d2444791 100644 --- a/src/musredit_qt6/mupp/mupp.cpp +++ b/src/musredit_qt6/mupp/mupp.cpp @@ -550,17 +550,26 @@ int main(int argc, char *argv[]) } QCoreApplication *app = createApplication(argc, argv, guiFlag); + std::unique_ptr gui; + std::unique_ptr mupp_script; if (qobject_cast(app)) { // GUI - PmuppGui *gui = new PmuppGui(fln); + gui = std::make_unique(fln); + if (gui == nullptr) { + std::cerr << std::endl; + std::cerr << "*********" << std::endl; + std::cerr << "**ERROR** couldn't invoke mupp gui..." << std::endl; + std::cerr << "*********" << std::endl; + return -1; + } gui->setWindowTitle( "muSR Parameter Plotter" ); gui->resize( 800, 500 ); gui->show(); app->connect( app, SIGNAL( lastWindowClosed() ), app, SLOT( quit() ) ); - app->connect( app, SIGNAL( aboutToQuit() ), gui, SLOT( aboutToQuit() ) ); + app->connect( app, SIGNAL( aboutToQuit() ), gui.get(), SLOT( aboutToQuit() ) ); } else { // scripting - PmuppScript *mupp_script = new PmuppScript(script); - if (mupp_script == 0) { + mupp_script = std::make_unique(script); + if (mupp_script == nullptr) { std::cerr << std::endl; std::cerr << "*********" << std::endl; std::cerr << "**ERROR** couldn't invoke script class..." << std::endl; @@ -569,10 +578,10 @@ int main(int argc, char *argv[]) } // This will cause the application to exit when the task signals finished. - QObject::connect( mupp_script, SIGNAL( finished() ), app, SLOT( quit() ) ); + QObject::connect( mupp_script.get(), SIGNAL( finished() ), app, SLOT( quit() ) ); // This will run the task from the application event loop. - QTimer::singleShot(0, mupp_script, SLOT( executeScript() ) ); + QTimer::singleShot(0, mupp_script.get(), SLOT( executeScript() ) ); } return app->exec();