QtcProcess: Fix crash when logging process stats

Change-Id: I204366a008dea91d1b2b946689c7598fe9ab009c
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2022-02-28 15:36:37 +01:00
parent 7b234e0fae
commit 92de389a61

View File

@@ -711,28 +711,31 @@ QtcProcess::QtcProcess(QObject *parent)
if (processLog().isDebugEnabled()) {
connect(this, &QtcProcess::finished, [this] {
if (const QVariant n = d->m_process.get()->property(QTC_PROCESS_NUMBER); n.isValid()) {
using namespace std::chrono;
const quint64 msSinceEpoc =
duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
const quint64 msStarted =
d->m_process.get()->property(QTC_PROCESS_STARTTIME).toULongLong();
const quint64 msElapsed = msSinceEpoc - msStarted;
if (!d->m_process.get())
return;
const QVariant n = d->m_process.get()->property(QTC_PROCESS_NUMBER);
if (!n.isValid())
return;
using namespace std::chrono;
const quint64 msSinceEpoc =
duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
const quint64 msStarted =
d->m_process.get()->property(QTC_PROCESS_STARTTIME).toULongLong();
const quint64 msElapsed = msSinceEpoc - msStarted;
const int number = n.toInt();
qCDebug(processLog).nospace() << "Process " << number << " finished: "
<< "result=" << result()
<< ", ex=" << exitCode()
<< ", " << stdOut().size() << " bytes stdout"
<< ", " << stdErr().size() << " bytes stderr"
<< ", " << msElapsed << " ms elapsed";
if (processStdoutLog().isDebugEnabled() && !stdOut().isEmpty())
qCDebug(processStdoutLog).nospace()
<< "Process " << number << " sdout: " << stdOut();
if (processStderrLog().isDebugEnabled() && !stdErr().isEmpty())
qCDebug(processStderrLog).nospace()
<< "Process " << number << " stderr: " << stdErr();
}
const int number = n.toInt();
qCDebug(processLog).nospace() << "Process " << number << " finished: "
<< "result=" << result()
<< ", ex=" << exitCode()
<< ", " << stdOut().size() << " bytes stdout"
<< ", " << stdErr().size() << " bytes stderr"
<< ", " << msElapsed << " ms elapsed";
if (processStdoutLog().isDebugEnabled() && !stdOut().isEmpty())
qCDebug(processStdoutLog).nospace()
<< "Process " << number << " sdout: " << stdOut();
if (processStderrLog().isDebugEnabled() && !stdErr().isEmpty())
qCDebug(processStderrLog).nospace()
<< "Process " << number << " stderr: " << stdErr();
});
}
}