[Interest] QProcess: child read from stdin - no data received?

André Somers andre at familiesomers.nl
Mon May 14 11:39:32 CEST 2012


Op 13-5-2012 19:51, Till Oliver Knoll schreef:
> Am 13.05.2012 um 18:36 schrieb Till Oliver Knoll<till.oliver.knoll at gmail.com>:
>
>> Hello,
>>
>> this seems to be an ever recurring topic: How does one get notified in a *child* process (started via QProcess) once there is data to be read on stdin (in a platform-independent matter - but for now mostly OS X)?
> I came to realise that stdin/out are really *text*-based and trying to re-open them in binary mode is also not guaranteed to work everywhere:
>
> http://bytes.com/topic/c/answers/213649-how-write-binary-data-stdout
>
> As I really want to send raw JPEG binary data from parent to child this IPC solution is a dead-end anyway.
>
>
> Next: QLocalServer/Socket. I assume in the parent process I start a QLocalServer, start a child process via QProcess and pass along the "server connect information" as arguments, and then in the child process connect to the parent process' server. That should hopefully give me a bi-directional (local socket or pipe) connection with "bytesAvailable" signals on both ends.
>
> It remains to be seen whether the parent process with *no* network entitlement ("OS X sandboxing") can actually create a local server...
>
> If that would fail, what remains is QSharedMemory. But to my understanding that would require to "poll some memory addresses" wheter the other process wants to "send a message". Not to mention that I need to send data of variable size (JPEG), so I would probably end up in a "memory-based block read/write protocol": "I have written 1024 KBytes of JPEG data into the shared memory block, more to follow (poll for ACK) - Ok, got it (poll for more data) - Here is the next block of 1024 KBytes - Ok, bring it on... - Here are the last 42 KBytes - Got it..." doh!
>
> I hope the local socket approach works...
>
How about using QSharedMemory for the actual JPEG data, and use either 
the QLocalServer/Socket or a StdIn/StdOut approach for the notifications 
that there is something to read? Seems more efficient than (de-) 
serializing images all the time. You could even use something like 
QxtRPCPeer[1] for the communication between the two programs.

André

[1] http://libqxt.bitbucket.org/doc/0.6/qxtrpcpeer.html#details




More information about the Interest mailing list