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

Christoph Spielmann spielc at gmail.com
Sun May 18 13:52:29 UTC 2008


Arno Rehn schrieb:
> 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!
>>     
Hi!
> Actually it's much easier to simply use Console.Read() or Console.ReadLine() 
>   
Well yes they work but somehow they seem to block the main event loop 
and the ui is not usable any more. So that's not what i want.
> 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.
>   
I tried out the fix you proposed and now the error message is gone but 
it's still not working as expected. If I use QTextStream as proposed by 
qt-documentation nothing happens (e.g when i use the Read*-methods of 
QTextStream) or i get a endless-loop if i use AtEnd() for example. When 
i use QFile directly using the Read*-methods i get very strange results:

Read(string,long): nothing happens
ReadLine(string,long): the method returns the correct length of bytes 
available but the string it's supposed to append the bytes to is not changed
ReadAll(): nothing happens

So i guess i found another problem... ;)

Christoph
>
>   




More information about the Kde-bindings mailing list