diff --git a/src/musredit_qt5/PTextEdit.cpp b/src/musredit_qt5/PTextEdit.cpp index da6133b2..c0672ea0 100644 --- a/src/musredit_qt5/PTextEdit.cpp +++ b/src/musredit_qt5/PTextEdit.cpp @@ -28,6 +28,7 @@ ***************************************************************************/ #include +#include using namespace std; #include @@ -1606,6 +1607,14 @@ void PTextEdit::musrWiz() arg << "--log"; QProcess *proc = new QProcess(this); + if (proc == nullptr) { + QMessageBox::critical(0, "**ERROR**", "Couldn't invoke QProcess!"); + return; + } + + // handle return status of musrWiz + connect(proc, static_cast(&QProcess::finished), + [=](int exitCode, QProcess::ExitStatus exitStatus){ exitStatusMusrWiz(exitCode, exitStatus); }); // make sure that the system environment variables are properly set QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); @@ -2491,6 +2500,58 @@ void PTextEdit::helpAboutQt() } +//---------------------------------------------------------------------------------------------------- +/** + * @brief PTextEdit::exitStatusMusrWiz + * @param exitCode + * @param exitStatus + */ +void PTextEdit::exitStatusMusrWiz(int exitCode, QProcess::ExitStatus exitStatus) +{ + if (exitStatus == QProcess::CrashExit) { + QMessageBox::critical(0, "**FATAL**", "musrWiz returned CrashExit."); + return; + } + + // dialog finished with reject + if (exitCode == 0) + return; + + // read .musrWiz.log + ifstream fin(".musrWiz.log", ifstream::in); + if (!fin.is_open()) { + QMessageBox::critical(0, "**ERROR**", "PTextEdit::exitStatusMusrWiz: couldn't read .musrWiz.log file."); + return; + } + char line[128]; + bool musrT0tag = false; + QString str, pathFileName(""); + while (fin.good()) { + fin.getline(line, 128); + str = line; + if (str.startsWith("path-file-name:")) { + pathFileName = str.mid(16); + } else if (str.startsWith("musrt0-tag: yes")) { + musrT0tag = true; + } + } + fin.close(); + + load(pathFileName); + + // in case there is a 1st empty tab "noname", remove it + QString tabStr = fTabWidget->tabText(0); + tabStr.remove('&'); // this is needed since the QTabWidget adds short-cut info as '&' to the tab name + if (tabStr == "noname") { // has to be the first, otherwise do nothing + fFileSystemWatcher->removePath("noname"); + + delete fTabWidget->widget(0); + } + + if (musrT0tag) + musrT0(); +} + //---------------------------------------------------------------------------------------------------- /** * @brief PTextEdit::existStatusMusrSetSteps diff --git a/src/musredit_qt5/PTextEdit.h b/src/musredit_qt5/PTextEdit.h index 9e1863d5..9307c837 100644 --- a/src/musredit_qt5/PTextEdit.h +++ b/src/musredit_qt5/PTextEdit.h @@ -142,6 +142,7 @@ private slots: void helpAboutQt(); void helpAbout(); + void exitStatusMusrWiz(int exitCode, QProcess::ExitStatus exitStatus); void exitStatusMusrSetSteps(int exitCode, QProcess::ExitStatus exitStatus); void fontChanged( const QFont &f );