From a49d9f5aefa6136d222c0eccbb2e4aea73fe4bda Mon Sep 17 00:00:00 2001 From: Adeel Asghar Date: Thu, 12 Jan 2017 16:39:18 +0100 Subject: [PATCH] Use the File* instead of QFile & QTextStream. Flush all streams when opening the CrashReportDialog so we get full logs. --- .../CrashReport/CrashReportDialog.cpp | 2 + OMEdit/OMEditGUI/OMC/OMCProxy.cpp | 49 +++++++++---------- OMEdit/OMEditGUI/OMC/OMCProxy.h | 6 +-- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/OMEdit/OMEditGUI/CrashReport/CrashReportDialog.cpp b/OMEdit/OMEditGUI/CrashReport/CrashReportDialog.cpp index 2ebf056ccce..28b98cab047 100644 --- a/OMEdit/OMEditGUI/CrashReport/CrashReportDialog.cpp +++ b/OMEdit/OMEditGUI/CrashReport/CrashReportDialog.cpp @@ -48,6 +48,8 @@ CrashReportDialog::CrashReportDialog() : QDialog(0) { + // flush all streams before making a crash report so we get full logs. + fflush(NULL); setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::crashReport)); setAttribute(Qt::WA_DeleteOnClose); // set heading diff --git a/OMEdit/OMEditGUI/OMC/OMCProxy.cpp b/OMEdit/OMEditGUI/OMC/OMCProxy.cpp index 6a65a933cab..cfda63c8adb 100644 --- a/OMEdit/OMEditGUI/OMC/OMCProxy.cpp +++ b/OMEdit/OMEditGUI/OMC/OMCProxy.cpp @@ -183,19 +183,11 @@ bool OMCProxy::initializeOMC() /* create the tmp path */ QString& tmpPath = Utilities::tempDirectory(); /* create a file to write OMEdit communication log */ - mCommunicationLogFile.setFileName(QString("%1omeditcommunication.log").arg(tmpPath)); - if (mCommunicationLogFile.open(QIODevice::WriteOnly | QIODevice::Text)) { - mCommunicationLogFileTextStream.setDevice(&mCommunicationLogFile); - mCommunicationLogFileTextStream.setCodec(Helper::utf8.toStdString().data()); - mCommunicationLogFileTextStream.setGenerateByteOrderMark(false); - } + QString communicationLogFilePath = QString("%1omeditcommunication.log").arg(tmpPath); + mpCommunicationLogFile = fopen(communicationLogFilePath.toStdString().c_str(), "w"); /* create a file to write OMEdit commands */ - mCommandsMosFile.setFileName(QString("%1omeditcommands.mos").arg(tmpPath)); - if (mCommandsMosFile.open(QIODevice::WriteOnly | QIODevice::Text)) { - mCommandsLogFileTextStream.setDevice(&mCommandsMosFile); - mCommandsLogFileTextStream.setCodec(Helper::utf8.toStdString().data()); - mCommandsLogFileTextStream.setGenerateByteOrderMark(false); - } + QString commandsLogFilePath = QString("%1omeditcommands.mos").arg(tmpPath); + mpCommandsLogFile = fopen(commandsLogFilePath.toStdString().c_str(), "w"); // read the locale QSettings *pSettings = Utilities::getApplicationSettings(); QLocale settingsLocale = QLocale(pSettings->value("language").toString()); @@ -237,14 +229,20 @@ bool OMCProxy::initializeOMC() } /*! - Stops the OpenModelica Compiler. Kill the process omc and also deletes the CORBA reference file. - \see startServer - */ + * \brief OMCProxy::quitOMC + * Quits the OpenModelica Compiler.\n + * Closes the log files. + * \see startServer + */ void OMCProxy::quitOMC() { sendCommand("quit()"); - mCommunicationLogFile.close(); - mCommandsMosFile.close(); + if (mpCommunicationLogFile) { + fclose(mpCommunicationLogFile); + } + if (mpCommandsLogFile) { + fclose(mpCommandsLogFile); + } } /*! @@ -331,15 +329,15 @@ void OMCProxy::logCommand(QString command, QTime *commandTime) mCurrentCommandIndex = mCommandsList.count(); mpExpressionTextBox->setText(""); // write the log to communication log file - if (mCommunicationLogFileTextStream.device()) { - mCommunicationLogFileTextStream << QString("%1 %2\n").arg(command).arg(commandTime->currentTime().toString("hh:mm:ss:zzz")); + if (mpCommunicationLogFile) { + fputs(QString("%1 %2\n").arg(command, commandTime->currentTime().toString("hh:mm:ss:zzz")).toStdString().c_str(), mpCommunicationLogFile); } // write commands mos file - if (mCommandsLogFileTextStream.device()) { + if (mpCommandsLogFile) { if (command.compare("quit()") == 0) { - mCommandsLogFileTextStream << QString("%1;\n").arg(command); + fputs(QString("%1;\n").arg(command).toStdString().c_str(), mpCommandsLogFile); } else { - mCommandsLogFileTextStream << QString("%1; getErrorString();\n").arg(command); + fputs(QString("%1; getErrorString();\n").arg(command).toStdString().c_str(), mpCommandsLogFile); } } } @@ -359,11 +357,10 @@ void OMCProxy::logResponse(QString response, QTime *responseTime) format.setFont(font); Utilities::insertText(mpOMCLoggerTextBox, response + "\n\n", format); // write the log to communication log file - if (mCommunicationLogFileTextStream.device()) { - mCommunicationLogFileTextStream << QString("%1 %2\n").arg(response).arg(responseTime->currentTime().toString("hh:mm:ss:zzz")); + if (mpCommunicationLogFile) { + fputs(QString("%1 %2\n").arg(response).arg(responseTime->currentTime().toString("hh:mm:ss:zzz")).toStdString().c_str(), mpCommunicationLogFile); mTotalOMCCallsTime += (double)responseTime->elapsed() / 1000; - mCommunicationLogFileTextStream << QString("%1 secs (%2 secs)\n\n").arg(QString::number((double)responseTime->elapsed() / 1000)) - .arg(QString::number(mTotalOMCCallsTime)); + fputs(QString("%1 secs (%2 secs)\n\n").arg(QString::number((double)responseTime->elapsed() / 1000)).arg(QString::number(mTotalOMCCallsTime)).toStdString().c_str(), mpCommunicationLogFile); } } diff --git a/OMEdit/OMEditGUI/OMC/OMCProxy.h b/OMEdit/OMEditGUI/OMC/OMCProxy.h index f3a92c9a9bb..a0146aae6d2 100644 --- a/OMEdit/OMEditGUI/OMC/OMCProxy.h +++ b/OMEdit/OMEditGUI/OMC/OMCProxy.h @@ -74,10 +74,8 @@ class OMCProxy : public QObject QString mObjectRefFile; QList mCommandsList; int mCurrentCommandIndex; - QFile mCommunicationLogFile; - QTextStream mCommunicationLogFileTextStream; - QFile mCommandsMosFile; - QTextStream mCommandsLogFileTextStream; + FILE *mpCommunicationLogFile; + FILE *mpCommandsLogFile; double mTotalOMCCallsTime; QList mUnitConversionList; QMap > mDerivedUnitsMap;