Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 8

Qt-interest Archive, October 2006
How does Stdin should be handled in a Qapplication ?


Message 1 in thread

Hi all,

I am setting up an IPC using stdin / stdout / stderr.

The doc of the QProcess is very clear.

But... I cannot figure out how the **child** process should handle stdin
events...


How does a Qt application handles its stdin ?
Is there a QProcess-like API for the **child** process ?
Or a specific QEvent ?
Is it in QApplication ? Elsewhere ?


These are quite silly question but... I did not find answer after browsing
the doc quite a long time...

Sorry, and thx for your quick answers to this quick question ;=)

Best-
Nicolas

--
 [ signature omitted ] 

Message 2 in thread

Nicolas Castagne wrote:

> Hi all,
> 
> I am setting up an IPC using stdin / stdout / stderr.
> 
> The doc of the QProcess is very clear.
> 
> But... I cannot figure out how the **child** process should handle stdin
> events...
> 
> 
> How does a Qt application handles its stdin ?
> Is there a QProcess-like API for the **child** process ?
> Or a specific QEvent ?
> Is it in QApplication ? Elsewhere ?
> 
> 
> These are quite silly question but... I did not find answer after browsing
> the doc quite a long time...
> 
> Sorry, and thx for your quick answers to this quick question ;=)

stdin (and stdout and stderr, for that matter) have standard file
descriptors, and you can use them just like a file. Just open them with
that special descriptor (0 for stdin, 1 for stdout and 2 for stderr; but
they are defined in stdio.h as well) and you're done. A bit of googling
would have have provided you with the answer...

André

-- 
 [ signature omitted ] 

Message 3 in thread

Thx much AndrÃ,

Well, I thought Qt could have offered a dedicated, ready to use mean for
reading stdin.


I've tried using a QFile opened on stdin, but without true sucess.


Problems I have are :

1/ the QFile for stdin in the **child** process never emits the signal
                void readyRead();

   How should I detetect that data have been writen to my process' stdin ?


For the moment, I use a QTimer and check regularly for available data... 
Other problems are then :

2/ QFile::bytesAvailable() always returns 0, even though my **parent**
QProcess wrote bytes + end-of-line.

3/ Though, calling QFile::readData ( char * data, qint64 maxSize ) does read
the data writen by the **parent** process.

4/ but only once every two sent messages (both the last, and previous
messages are then read).

5/ etc.


So, my top questions are still :

What are the key points I should follow to set up a portable IPC using
stdin/stdout ?

Is it recommanded not to use stdin/stdout, but another IPC mean
(sockets...) ? Why ?



Indeed, the QProcess class is veryclear on the subject of stdin/stdout... 

But the doc and qt-interest say nothing on what I should do on the **child**
process' side, while what should be done is clearly not evidence (cf.
various questions on qt-interest, and the problems I have myself).



Thx in advance,
Best-

Nicolas




Well, I consider 

Andrà Somers wrote:

> Nicolas Castagne wrote:
> 
>> Hi all,
>> 
>> I am setting up an IPC using stdin / stdout / stderr.
>> 
>> The doc of the QProcess is very clear.
>> 
>> But... I cannot figure out how the **child** process should handle stdin
>> events...
>> 
>> 
>> How does a Qt application handles its stdin ?
>> Is there a QProcess-like API for the **child** process ?
>> Or a specific QEvent ?
>> Is it in QApplication ? Elsewhere ?
>> 
>> 
>> These are quite silly question but... I did not find answer after
>> browsing the doc quite a long time...
>> 
>> Sorry, and thx for your quick answers to this quick question ;=)
> 
> stdin (and stdout and stderr, for that matter) have standard file
> descriptors, and you can use them just like a file. Just open them with
> that special descriptor (0 for stdin, 1 for stdout and 2 for stderr; but
> they are defined in stdio.h as well) and you're done. A bit of googling
> would have have provided you with the answer...
> 
> AndrÃ
> 

--
 [ signature omitted ]