Grabinuo
Grabinuo

Reputation: 380

How to Redirct QProcess StandardOutput

I am using two instances of QProcess. In some portions of my code I need process1 to redirect its output to process2.
By following Qt documentation I can use QProcess.setStandardOutput(), which is great. But, later on I have to disable this in code. How do I redirect its output to the default behavior (stdout)? I have tried process1 = QProcess(), but it did not work.

process1 = QProcess()
process2 = QProcess()
process1.setStandardOutputProcess(process2)
process1.start("command1")
process2.start("command2")

process1.setStandardOutputProcess(QProcess())
works but is that the correct way of redistricting? Or am I creating a new "uneccessry" object?

Upvotes: 1

Views: 198

Answers (1)

Grabinuo
Grabinuo

Reputation: 380

After reporting this as a bug on Qt bug tracker.

I have received the following reply:

That is a limitation of Qt, QProcess::setStandardOutputProcess(Qprocess *destination) expects a non-null pointer; it is not meant to be changed at runtime.

My workaround to this issue was to use process1.setStandardOutputProcess(QProcess()).

EDIT
I asked if there is a workaround and received the following reply

Is there a recommended workaround?

He replied

No. It is not designed to allow for a change of device (since there are most likely I/O buffers involved). Similarly, when doing something like

ls -l | fgrep "bla"

in the shell, there is no way the change the 2nd process in mid-flight, either.

Upvotes: 1

Related Questions