[Interest] QProcess unbuffered

Thiago Macieira thiago.macieira at intel.com
Mon Mar 6 03:29:33 CET 2023

On Sunday, 5 March 2023 17:11:13 PST Scott Bloom wrote:
> I have an external executable (mkvalidator from
> https://www.matroska.org/downloads/mkvalidator.html
> It never flushes the output, and it uses linefeed without carriage returns
> to overwrite existing text on the output.

You've described the standard for Unix processes. There's no carriage return 
and stdout is fully buffered when not connected to a terminal.

> The problem is, when I run it via QProcess (on windows, Qt 5.15.10), I get
> zero output until the process ends.  As if it was buffered, and the output
> was finally flushed
> When running from the command line, I do get output continuously during the
> processing.
> I setup a timer to waitForRead, didn't do anything. I cant seem to force the
> QProcess to read all stdout or stderror info.

You don't need a timer on waitForRead because you have the readyRead() signal.

Anyway, the problem is that your process is not writing. It's buffering its 
output until later. This is not a QProcess problem; you must force the child 
process to write.

Many programs that do this type of interaction have a command-line option to 
switch back to line-buffered. For those that don't, you can use the /usr/bin/
stdbuf tool to change the buffering semantics, but I don't know how it works, 
just that it does on Linux, so it may not on Windows.

Since you're on Windows and this application is not part of Windows itself, it 
stands to reason you're compiling it yourself and distributing with your 
application. So just modify it to be line-buffered.

Thiago Macieira - thiago.macieira (AT) intel.com
  Cloud Software Architect - Intel DCAI Cloud Engineering
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5152 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20230305/d60fbe6f/attachment.bin>

More information about the Interest mailing list