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