<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi everybody!<br>
<br>
I'm working on an application which receives commands from stdin. After
a bit of googleing i found the following solution for doing that using
qt (the original example code was not for qyoto but i assumed it would
work similarly so i just adepted the code...):<br>
<br>
<span class="sb_messagebody">
<pre><code><span style="color: rgb(0, 0, 0);"><span
 style="color: rgb(0, 119, 0);">...
public </span><span style="color: rgb(0, 0, 187);">QFile stdin</span><span
 style="color: rgb(0, 119, 0);">;
public </span><span style="color: rgb(0, 0, 187);">QSocketNotifier stdinNot</span><span
 style="color: rgb(0, 119, 0);">;
...
</span><span style="color: rgb(0, 0, 187);">this</span><span
 style="color: rgb(0, 119, 0);">.</span><span
 style="color: rgb(0, 0, 187);">stdin</span><span
 style="color: rgb(0, 119, 0);">=new </span><span
 style="color: rgb(0, 0, 187);">QFile</span><span
 style="color: rgb(0, 119, 0);">();
</span><span style="color: rgb(0, 0, 187);">this</span><span
 style="color: rgb(0, 119, 0);">.</span><span
 style="color: rgb(0, 0, 187);">stdin</span><span
 style="color: rgb(0, 119, 0);">.</span><span
 style="color: rgb(0, 0, 187);">Open</span><span
 style="color: rgb(0, 119, 0);">(</span><span
 style="color: rgb(0, 0, 187);">0</span><span
 style="color: rgb(0, 119, 0);">,(int) </span><span
 style="color: rgb(0, 0, 187);">QIODevice</span><span
 style="color: rgb(0, 119, 0);">.</span><span
 style="color: rgb(0, 0, 187);">OpenModeFlag</span><span
 style="color: rgb(0, 119, 0);">.</span><span
 style="color: rgb(0, 0, 187);">ReadOnly</span><span
 style="color: rgb(0, 119, 0);">); </span><span
 style="color: rgb(255, 128, 0);">//open stdin for reading

</span><span style="color: rgb(0, 0, 187);">this</span><span
 style="color: rgb(0, 119, 0);">.</span><span
 style="color: rgb(0, 0, 187);">stdinNot</span><span
 style="color: rgb(0, 119, 0);">=new </span><span
 style="color: rgb(0, 0, 187);">QSocketNotifier</span><span
 style="color: rgb(0, 119, 0);">(</span><span
 style="color: rgb(0, 0, 187);">0</span><span
 style="color: rgb(0, 119, 0);">,</span><span
 style="color: rgb(0, 0, 187);">QSocketNotifier</span><span
 style="color: rgb(0, 119, 0);">.</span><span
 style="color: rgb(0, 0, 187);">TypeOf</span><span
 style="color: rgb(0, 119, 0);">.</span><span
 style="color: rgb(0, 0, 187);">Read</span><span
 style="color: rgb(0, 119, 0);">);
</span><span style="color: rgb(0, 0, 187);">QObject</span><span
 style="color: rgb(0, 119, 0);">.</span><span
 style="color: rgb(0, 0, 187);">Connect</span><span
 style="color: rgb(0, 119, 0);">(</span><span
 style="color: rgb(0, 0, 187);">this</span><span
 style="color: rgb(0, 119, 0);">.</span><span
 style="color: rgb(0, 0, 187);">stdinNot</span><span
 style="color: rgb(0, 119, 0);">, </span><span
 style="color: rgb(0, 0, 187);">Qt</span><span
 style="color: rgb(0, 119, 0);">.</span><span
 style="color: rgb(0, 0, 187);">SIGNAL</span><span
 style="color: rgb(0, 119, 0);">(</span><span
 style="color: rgb(221, 0, 0);">"activated(int)"</span><span
 style="color: rgb(0, 119, 0);">),</span><span
 style="color: rgb(0, 0, 187);">this</span><span
 style="color: rgb(0, 119, 0);">,</span><span
 style="color: rgb(0, 0, 187);">Qt</span><span
 style="color: rgb(0, 119, 0);">.</span><span
 style="color: rgb(0, 0, 187);">SLOT</span><span
 style="color: rgb(0, 119, 0);">(</span><span
 style="color: rgb(221, 0, 0);">"DataReadyOnStdin()"</span><span
 style="color: rgb(0, 119, 0);">));

...
[</span><span style="color: rgb(0, 0, 187);">Q_SLOT</span><span
 style="color: rgb(0, 119, 0);">]
public </span><span style="color: rgb(0, 0, 187);">void DataReadyOnStdin</span><span
 style="color: rgb(0, 119, 0);">() {
    </span><span style="color: rgb(0, 0, 187);">Console</span><span
 style="color: rgb(0, 119, 0);">.</span><span
 style="color: rgb(0, 0, 187);">WriteLine</span><span
 style="color: rgb(0, 119, 0);">(</span><span
 style="color: rgb(0, 0, 187);">this</span><span
 style="color: rgb(0, 119, 0);">.</span><span
 style="color: rgb(0, 0, 187);">stdin</span><span
 style="color: rgb(0, 119, 0);">.</span><span
 style="color: rgb(0, 0, 187);">Read</span><span
 style="color: rgb(0, 119, 0);">(</span><span
 style="color: rgb(221, 0, 0);">""</span><span
 style="color: rgb(0, 119, 0);">,</span><span
 style="color: rgb(0, 0, 187);">255L</span><span
 style="color: rgb(0, 119, 0);">));
}
...
</span></span></code></pre>
</span><br>
i have to use both a QSocketNotifier and QFile to get notified as soon
as we have acitvity on stdin, because according to the QT-documentation
QFile does NOT emit the readyRead() signal (which is a shame in my eyes
but okey, i could live with the above solution if it would work... ;) ).<br>
<br>
As soon as i enter something to stdin the activiated(int) signal gets
emitted as expected but as soon as i actually try to read from stdin
using the QFile-object stdin i get this:<br>
<br>
Cannot handle 'qint64' as argument to QIODevice::read<br>
<br>
So what is the correct way to read data from stdin within a
qyoto-gui-application? I'm open for all suggestion as i am kinda out of
ideas how to solve this task!<br>
<br>
Thanks in advance,<br>
<br>
Christoph<br>
</body>
</html>