[Qt-interest] QProcess stdout bug
Jan Kundrát
jkt at gentoo.org
Tue Apr 28 17:47:43 CEST 2009
Carlos Rei wrote:
> Now if I comment out the usleep on line foo.cpp:50 and run foo again,
> the program just stalls and I do not get any output. Why is the usleep
> needed?
Don't use it like that. It's pure chance that the usleep() call helps
here. If you want to go the Qt way, just connect readyRead() to a custom
slot that will read everything which is *already* available and do
something with it. Alternatively, if you want to start processing when
the launched program finished, find another signal of QProcess.
The bug in your code is that you:
a) don't let the event loop process everything which is required (as the
events might occur after the processEvents finishes(
b) confuse QProcess::canReadLineStdout(), which returns true if and only
if you can read a full line right now, with a hypothetical function
"wait for the exit of the child process and then return if you can read
data from its buffered stdout".
Also, switching to Qt4 might be a really good idea :).
Cheers,
-jkt
--
cd /local/pub && more beer > /dev/mouth
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090428/12b4e241/attachment.bin
More information about the Qt-interest-old
mailing list