[Qt-interest] QProcess not emitting readyRead for blocking processes

Thiago Macieira thiago at kde.org
Tue Sep 7 17:11:39 CEST 2010


Em Terça-feira 07 Setembro 2010, às 15:11:14, Rohan Prabhu escreveu:
> it is working properly. As in, the singal is emitted and the connected
> slot outputs it. I am having a problem with the following programs:
> 
> 1. tail [with the -f option]
> 2. wget
> 3. ssh

> Anyone has any clues as to why?

Are you sure it *never* emits? Even if you wait a long time?

If it does, and I think it does, note that this is not a QProcess limitation, 
but a libc one. When the stdout of a process is not a TTY, libc's stdio 
defaults to full-buffering mode, as opposed to the more usual line-buffered 
mode.

That means the process doesn't write to the pipe at every finished line, as 
you'd expect, but instead when the buffer fills.

You have three options:

1) just wait, because the data is being written and will eventually arrive

2) modify the target application to force it to use line-buffering. Some tools 
have that option, others you may have to modify the source code. Add this to 
some place:

	setlinebuf(stdio);		// BSD extension
or
	setvbuf(stdio, (char *) NULL, _IOLBF, 0); /* ISO C */

3) use a terminal instead of a pipe. This requires that you know how to open a 
terminal master on your system. You can do it with QProcess but you need to 
write some code for it. The upside is that no tools need to be modified.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100907/7dd66435/attachment.bin 


More information about the Qt-interest-old mailing list