[Kde-bindings] Qyoto: Reading from stdin from a gui-application

Arno Rehn arno at arnorehn.de
Sun May 18 11:01:22 UTC 2008


Am Sonntag 18 Mai 2008 11:36:57 schrieb Christoph Spielmann:
> Hi everybody!
>
> 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...):
> |...
>
> public QFile stdin;
> public QSocketNotifier stdinNot;
> ...
> this.stdin=new QFile();
> this.stdin.Open(0,(int) QIODevice.OpenModeFlag.ReadOnly); //open stdin for
> reading
>
> this.stdinNot=new QSocketNotifier(0,QSocketNotifier.TypeOf.Read);
> QObject.Connect(this.stdinNot,
> Qt.SIGNAL("activated(int)"),this,Qt.SLOT("DataReadyOnStdin()"));
>
> ...
> [Q_SLOT]
> public void DataReadyOnStdin() {
>     Console.WriteLine(this.stdin.Read("",255L));
> }
> ...
>
>
>
> 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... ;) ).
>
> 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:
>
> Cannot handle 'qint64' as argument to QIODevice::read
>
> 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!
Actually it's much easier to simply use Console.Read() or Console.ReadLine() 
from the System namespace, but it should also work with the Qt classes. The 
error indicates that we currently don't handle qint64, which should be quite 
easy to fix. I'll look into this.


-- 
Arno Rehn
arno at arnorehn.de



More information about the Kde-bindings mailing list