[Kde-bindings] C#, Qyoto, Qt - How to read output from QProcess?

Arno Rehn arno at arnorehn.de
Fri Feb 19 18:42:27 UTC 2010


On Friday 19 February 2010 11:06:39 Richard Dale wrote:
> On Friday 19 February 2010 06:02:47 am linuxoidoz at yahoo.com.au wrote:
> > All I've done was to move
> > 
> > proc = new QProcess(this);
> > 
> > from the MainWindow class constructor to the slot and it's working now,
> > that is on readyReadStandardOutput(), it writes my text into a QTextEdit
> > 
> > box. But how can I output the process output into the QTextEdit? This:
> >                [Q_SLOT]
> >                private void updateLog() {
> >                
> >                        QByteArray data = proc.ReadAllStandardOutput();
> >                        QTextCodec codec =
> >                        QTextCodec.CodecForUtfText(data); string str =
> >                        codec.ToUnicode(data);
> >                        txtEdit.Append(str);
> >                
> >                }
> > 
> > only crashes the app with "System.MemberAccessException: Cannot create an
> > instance of Qyoto.QTextCodec because it is an abstract class". I used the
> > Qt C++ example and modified it to C#. There are many examples which show
> > you can cast byte array type to string with QString(byteArray), but
> > there's no QString in Qyoto, and (String)byteArray complains it can't
> > convert QBytaArray to string. I'd appreciate your help. Thank you.
> 
> We've added a QByteArray.ToArray() method to convert it to a byte[], which
> you can then convert to a string with something like
> System.Text.Encoding.ASCII.GetString.
Or simply use QByteArray.ConstData() which should give you a C# string 
directly.

-- 
Arno Rehn
arno at arnorehn.de



More information about the Kde-bindings mailing list