QtcProcess: Add processChannelMode() getter

Use ProcessInterface's setup data when handling
readyRead signals. In this way the user may still
change this setting, also when QtcProcess is running,
as a preparation for the next run. In this way this
works like all other QtcProcess mutators.

Change-Id: Ie80475e322162ce109fb95468ce858f9c98eefa9
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-04-25 14:15:23 +02:00
parent 88d148f01f
commit c81a7b5c70
3 changed files with 13 additions and 5 deletions

View File

@@ -35,6 +35,8 @@
namespace Utils {
namespace Internal { class QtcProcessPrivate; }
class QTCREATOR_UTILS_EXPORT ProcessSetupData
{
public:
@@ -121,6 +123,7 @@ private:
virtual bool waitForFinished(int msecs) = 0;
friend class QtcProcess;
friend class Internal::QtcProcessPrivate;
};
} // namespace Utils

View File

@@ -1142,9 +1142,13 @@ qint64 QtcProcess::applicationMainThreadId() const
return d->m_applicationMainThreadId;
}
QProcess::ProcessChannelMode QtcProcess::processChannelMode() const
{
return d->m_setup.m_processChannelMode;
}
void QtcProcess::setProcessChannelMode(QProcess::ProcessChannelMode mode)
{
QTC_CHECK(state() == QProcess::NotRunning);
d->m_setup.m_processChannelMode = mode;
}
@@ -1569,16 +1573,16 @@ void QtcProcessPrivate::handleReadyRead(const QByteArray &outputData, const QByt
m_hangTimerCount = 0;
// TODO: store a copy of m_processChannelMode on start()? Currently we assert that state
// is NotRunning when setting the process channel mode.
if (m_setup.m_processChannelMode == QProcess::ForwardedOutputChannel
|| m_setup.m_processChannelMode == QProcess::ForwardedChannels) {
if (m_process->m_setup.m_processChannelMode == QProcess::ForwardedOutputChannel
|| m_process->m_setup.m_processChannelMode == QProcess::ForwardedChannels) {
std::cout << outputData.constData() << std::flush;
} else {
m_stdOut.append(outputData);
if (!outputData.isEmpty())
emitReadyReadStandardOutput();
}
if (m_setup.m_processChannelMode == QProcess::ForwardedErrorChannel
|| m_setup.m_processChannelMode == QProcess::ForwardedChannels) {
if (m_process->m_setup.m_processChannelMode == QProcess::ForwardedErrorChannel
|| m_process->m_setup.m_processChannelMode == QProcess::ForwardedChannels) {
std::cerr << errorData.constData() << std::flush;
} else {
m_stdErr.append(errorData);

View File

@@ -121,6 +121,7 @@ public:
bool isRunAsRoot() const;
void setAbortOnMetaChars(bool abort);
QProcess::ProcessChannelMode processChannelMode() const;
void setProcessChannelMode(QProcess::ProcessChannelMode mode);
void setStandardInputFile(const QString &inputFile);