[Interest] Qt and bash scripts

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Mon Jul 2 06:41:12 CEST 2012


On Mon, Jul 2, 2012 at 7:08 AM, Phil <phil_lor at bigpond.com> wrote:
> On 01/07/12 22:27, Thiago Macieira wrote:
>> On domingo, 1 de julho de 2012 22.12.50, Phil wrote:
>>> {
>>>       QProcess myProcess;
>>>       QString str;
>>>
>>>       myProcess.start( "ls" );
>>>
>>>       if (!myProcess.waitForFinished())
>>>            qDebug()<<  "Make failed:"<<  myProcess.errorString();
>>>        else
>>>       {
>>>            qDebug()<<  "Make output:"<<  myProcess.readAll();
>>>
>>>            str = myProcess.readAll();
>>>            qDebug()<<  "string = "<<  str;
>>>
>>>           QByteArray array = myProcess.readAllStandardOutput();
>>>
>>>           qDebug()<<  "array size = "<<  array.size();
>>>
>>>       }
>>> }
>>>
>>> The string = "" and the array size = 0;
>>
>> You're reading stdout three times: by default, read and readAll are connected
>> to stdout. Did you mean to readAllStandardError() in the second check?
>>
>> I have to ask: are there any files to be listed in the current directory of the
>> application?
>>
>> What showed up in the "Make output" line?
>>
>
> Thanks Thiago and Rene for your replies, very much appreciated.
>
> I don't think I'm expressing my question clearly.
>
> The "Make output" line does display the contents of the directory.
> However, what I want is to have a string or a string list to contain the
> directory listing so that I can display the directory files in a dialog
> box rather than on the console screen.

As Thiago mentioned, why aren't you using QDir/QFileInfo for this
requirement? You don't need to run 'ls' to get a dir's contents. Or
did you use ls just to illustrate your problem?

Also, in your sample code, you're calling myProcess.readAll(), twice!
The first call to readAll() would empty your process' output buffer
and hence your second call is not showing any data. Just call
myProcess.readAllStandardOutput() once and store the contents in your
bytearray.

HTH,
-mandeep


>
> This is just a simplified example of what I'd like to achieve.
>
> --
> Regards,
> Phil
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list