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

Thiago Macieira thiago.macieira at intel.com
Mon Feb 20 07:16:42 CET 2023


On Friday, 17 February 2023 16:16:02 PST Philip Seeger wrote:
> 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.

That's correct. The name of the "wait For BytesWritten" method means it waits 
for the bytesWritten signal to be emitted. That is emitted when any byte gets 
written, not when all bytes finish writing.

If after the signal is emitted, bytesToWrite() is still too high for you, you 
can wait again until it drops to a low enough number.

-- 
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/20230219/1c5de3d1/attachment.bin>


More information about the Interest mailing list