mupp: got rid of some left over raw pointers by replacing them through smartpointers.

This commit is contained in:
suter_a 2023-11-03 07:54:52 +01:00
parent 4747fbc77d
commit 3c2b0322c0
2 changed files with 30 additions and 12 deletions

View File

@ -598,17 +598,26 @@ int main(int argc, char *argv[])
}
QCoreApplication *app = createApplication(argc, argv, guiFlag);
std::unique_ptr<PmuppGui> gui;
std::unique_ptr<PmuppScript> mupp_script;
if (qobject_cast<QApplication *>(app)) { // GUI
PmuppGui *gui = new PmuppGui(fln);
gui = std::make_unique<PmuppGui>(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<PmuppScript>(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();

View File

@ -550,17 +550,26 @@ int main(int argc, char *argv[])
}
QCoreApplication *app = createApplication(argc, argv, guiFlag);
std::unique_ptr<PmuppGui> gui;
std::unique_ptr<PmuppScript> mupp_script;
if (qobject_cast<QApplication *>(app)) { // GUI
PmuppGui *gui = new PmuppGui(fln);
gui = std::make_unique<PmuppGui>(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<PmuppScript>(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();