Output of QProcess is delayed
-
Hi!
I have developed a GUI application that launches a command line tool. Basically, it gets some data from the GUI, saves such data in a file, and then runs the command line tool passing the name of this file as its unique parameter.
To do it, I use a QProcess, and connect the typical signals (for output, error, end of the process...) to my own slots. It works.
HOWEVER: the output of the underlying command line is noticeably delayed. This tool takes some time to complete, and every now and then it issues a message stating what's the part of the problem it is working on. When I run the command line manually, I get these messages as soon as the tool reaches the point where the corresponding phase of the process is executed.
However, when I embed it via QProcess, most of the messages are shown only when the command line tool has finished. This means that the user gets impatient about having no feedback...
Is there anything I can do to at least alleviate this problem?
Thanks!
-
@bleriot13 Please show how exactly you're using QProcess.
Especially how your read stdout.
Do you block the event loop somewhere? -
And does your program properly flush it's output to stdout (std::endl/std::flush?)
-
@bleriot13
As @Christian-Ehrlicher says, except I'm assuming the "other program" is not yours. Its output is likely to buffered when writing to a pipe rather than the terminal/command line. Try running something likeother | cat
from the command line and see how it behaves delay-wise. -
Dear @Christian-Ehrlicher, yours was the solution!
I wrote not only the GUI but also the command line app. I only had to add a std::flush command at the end of every message in the command line one and the problem was solved.
THANK YOU VERY MUCH!!!