fix: Use QTextStream to write to stdout and stderr
Only use `Qt::endl` when writing to the output stream; `Q_EMIT newLine` should not include a trailing newline because `appendPlainText` doesn't expect one.
This commit is contained in:
parent
c8408c4823
commit
c62b4ec068
1 changed files with 8 additions and 5 deletions
|
|
@ -36,18 +36,21 @@ QString printLine(FILE *out, const QString &type, const QString &message, const
|
||||||
stream << "\n\t" + fileLine;
|
stream << "\n\t" + fileLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto logLineBytes = logLine.toUtf8();
|
// We must return a non-terminated log line, but before returning,
|
||||||
auto logLine_c = logLineBytes.constData();
|
// stdout/stderr and Windows debug output all expect a terminated line.
|
||||||
|
QString terminatedLogLine = logLine;
|
||||||
|
QTextStream terminatedStream(&terminatedLogLine);
|
||||||
|
terminatedStream << Qt::endl;
|
||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
// Debug output is viewable using either VS Code, Visual Studio, DebugView, or
|
// Debug output is viewable using either VS Code, Visual Studio, DebugView, or
|
||||||
// DbgView++ (only one can be used at once). It's important to send output to
|
// DbgView++ (only one can be used at once). It's important to send output to
|
||||||
// the debug output API, because it's difficult to view stdout and stderr from
|
// the debug output API, because it's difficult to view stdout and stderr from
|
||||||
// a Windows GUI app.
|
// a Windows GUI app.
|
||||||
OutputDebugStringA(logLine_c);
|
OutputDebugStringA(terminatedLogLine.toLocal8Bit().constData());
|
||||||
#else
|
#else
|
||||||
fprintf(out, "%s", logLine_c);
|
QTextStream outStream(out);
|
||||||
fflush(out);
|
outStream << terminatedLogLine;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return logLine;
|
return logLine;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue