[Qt-interest] Problem with sending binary data to stdin of QProcess child.
Andreas Pakulat
apaku at gmx.de
Sun Jan 11 16:12:57 CET 2009
On 10.01.09 13:16:27, Bart van Deenen wrote:
> 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.
Well, you're not closing or flushing stdin of the process, so the data
might still be in some buffer (Qt or native). So if you don't need stdin
anymore, just close it on the sender side. Else at least flush it after
you've written your chunk of data.
Andreas
--
Blow it out your ear.
More information about the Qt-interest-old
mailing list