[Qt-interest] QProcess stdout bug

Carlos Rei car at vectorcast.com
Tue Apr 28 17:02:27 CEST 2009


Compiler: gcc version 4.1.2 (Ubuntu 4.1.2-0ubuntu4)
OS: Linux 2.6.20-16-server #2 SMP Thu Jun 7 20:26:23 UTC 2007 i686 GNU/Linux
Qt: 4.1.   Used qmake to generate Makefile


Hello,

I was wondering why we need to call usleep() after qApp->processEvents in 
order to read stdout.  I've attached two files foo.h and foo.cpp.  To 
reproduce the bug change foo.cpp:41 from "some_program" to a program with 
the following code:
#include <iostream>
#include <cstdlib>

int bar( int i )
{
   for( int j = 0; j < i; ++j )
   { std::cout << j << " of " << i << std::endl; }
   return 0;
}

int main( int argc, char** argv)
{
   std::cout << "In this function" << std::endl;
   int i = bar( std::atoi( argv[ 1 ] ) );
   return 0;
}


Run foo (from the attached files foo.h and foo.cpp) and notice that the 
tick slot (connected to QTimer timeout signal) is called and the output 
from the some_program is read in properly.

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?

Any help would be greatly appreciated. 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: foo.cpp
Url: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090428/aeb99cf6/attachment.pl 
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: foo.h
Url: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090428/aeb99cf6/attachment.h 


More information about the Qt-interest-old mailing list