[Interest] Flush after QProcess::write to prevent it from filling writeBuffer

Philip Seeger philip at c0xc.net
Sat Feb 18 01:16:02 CET 2023

Hi there!

I'm writing 1M chunks of data to a QProcess in a loop until all input 
data is consumed. How do I wait after calling QProcess::write() until 
all data has been sent to the process before calling write() again?

As documented, I have tried to call waitForBytesWritten(-1) after 
write() but it only helps in the first iteration; then it does not seem 
to block until all bytes are sent to the process. The result is that my 
program uses almost 4G of RES memory if a 4G input file is being read 
and the loop finishes in a second. Closing QProcess actually sends the 
data to the process (takes minutes) and I don't see any progress.

Internally, Qt seems to use a QByteArray as writeBuffer and I could not 
find where it checks if it exceeds a maximum size.

I believe QProcess storing 4 GB of data in an internal buffer is wrong 
under any circumstances. Have I overlooked something in the 
documentation? How do I turn this off?

I can provide a minimal example.


More information about the Interest mailing list