[Qt-interest] Problem with sending binary data to stdin of QProcess child. There's no QProcess::flush

Bart van Deenen bvandeenen at infologic.nl
Mon Jan 12 11:02:10 CET 2009


On Mon, 2009-01-12 at 01:14 -0800, Scott Aron Bloom wrote:
> > I've done that, and it seems that the sending side is fine. I'm still
> > getting nothing on the receiving side though :-(
> > This is the code on the receiving side.
> > 
> > QFile f;
> > f.open(stdin, QFile::ReadOnly | QIODevice::Unbuffered);
> > 
> > while(true) {
> > 	std::cerr << "HERE while!" << std::endl;
> > 	if (bytesavailable == 0 ) {
> > 		qint64 bytesavailable = f.bytesAvailable();
> > 		usleep(1000000);
> > 		std::cerr << "no bytes available"<<std::endl;
> > 		continue;
> > 	}
> > 
> > 	QByteArray bytes = f.read(bytesavailable);
> > 	std::cerr << "after read!" << bytesavailable << std::endl;
> > 	...
> > }
> > 
> > Why oh why? Could it be the contents of my two bytes?  { 0x0A, 0x00 }
> > 
> > Thanks
> > 
> > Bart
> 
> So what happens if you change tohe loop to be...
> 
> While ( true )
> {
> 	if ( !f.waitForReadyRead( 1000000 ) )
> 		continue;
>   
>        QByteArray bytes = f.read( f.bytesAvailable() );
> .....
> }
> 
> Your bytes available value appears to be local to the wrong scope...  I
> don't know it could be an email bug :)

It is a copy paste bug. Your fix doesn't work unfortunately. the
waitForReadyRead(1000000) doesn't wait at all. I'm getting 'no bytes
available' messages at the speed of light, even when I'm running the sub
process standalone and not typing any data into it.
Thanks for all the help, but I'm going with sockets, this stuff is just
not working. 

Bart

void VideoCommandThread::run()
{

	QFile f;
	f.open(0, QFile::ReadOnly | QIODevice::Unbuffered);
	std::cerr << "HERE while!" << std::endl;

	while ( true )	{
	if ( !f.waitForReadyRead( 1000000 ) ){
		std::cerr << "no bytes available"<<std::endl;
		continue;
	}
	QByteArray bytes = f.read( f.bytesAvailable() );
	gpbvideo::VideoMessage message;
	bool ok =message.ParseFromArray(bytes.data(), bytes.length());
	std::cerr << "HERE!" << std::endl;
	if (!ok) {
		std::cerr << "can't parse data from input";
	}
	else {
		std::cerr << "Succesfully parsed command message" <<
		std::endl <<message.DebugString();
	}
	}
}





More information about the Qt-interest-old mailing list