[Qt-interest] Problem with sending binary data to stdin of QProcess child.

Bart van Deenen bvandeenen at infologic.nl
Sat Jan 10 13:16:27 CET 2009


Hi all

I'm starting a subprocess via QProcess, and am doing fine with receiving 
redirected data from the subprocess with QProcess::readAllStandardError and 
QProcess:readAllStandardOutput after catching the relevant signals.

I'm stuck with getting data from the parent process to the child process 
though, and I don't see where I'm going wrong.

On the sender side I have:

    std::string s=message.SerializeAsString();
    qint64 ct = process.write(s.data(), s.length());
    if ( ct != s.length() ) {
        qFatal("Communication to child wrong. message length = %d, but %d 
bytes written\n", s.length(),(int)ct) ;
    }
    else {
        qDebug() << "Wrote " << ct << "bytes to child process";
    }

  the std::string s is a google protocol buffer encoded string, i.e. binary 
blobs. The current test message has a length of 2 bytes, and I always receive 
the message "Wrote 2 bytes to child process" so that goes well.

On the child receiver side I have a QThread, that should handle the commands 
on stdin, 
but It always tells me that there is no data available. ('debug' is a member 
QFile * for debugging purposes). I've also tried f.open(stdin,...) and 
std::cin and you name it.

void VideoCommandThread::run()
{
    QTextStream D(debug);
    QFile f;
    f.open(0, QFile::ReadOnly | QIODevice::Unbuffered);
    while(true) {
        qint64 bytesavailable = f.bytesAvailable();
        if (bytesavailable == 0 ) {
            D << "no data avaialble\n";
            usleep(500000);
            continue;
        }
        D << bytesavailable << " data avialable\n";
        QByteArray bytes = f.read(bytesavailable);
        ...
    }

Why is this not working? I don't get it. I've tried to see if there is some 
buffering going on somewhere, but I can't find it. There is no QProcess::flush() 
or something?


Help please ...

Bart van Deenen
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest






More information about the Qt-interest-old mailing list