[Qt-interest] Does QProcess::readAllStandardOutput have a limit?

Christian Gagneraud cgagneraud at techworks.ie
Thu Dec 2 22:20:39 CET 2010


On 12/02/2010 08:13 PM, Eric Clark wrote:
>> -----Original Message----- From:
>> qt-interest-bounces at trolltech.com [mailto:qt-interest-
>> bounces at trolltech.com] On Behalf Of Christian Gagneraud Sent:
>> Thursday, December 02, 2010 1:42 PM To:
>> qt-interest at trolltech.com Subject: Re: [Qt-interest] Does
>> QProcess::readAllStandardOutput have a limit?
>>
>> On 12/02/2010 07:16 PM, Eric Clark wrote:
>>> What do you mean by soon? I am not receiving any more calls to
>>> my slot connected to the readyReadStandardOutput signal. The
>>> process that is running outputs a bunch of startup text and
>>> then goes into an infinite loop waiting to receive commands. I
>>> have waited a while (minutes) after the process was started and
>>> I do not receive any more signals that the standard output is
>>> ready to be read.
>>
>> Have you tried the QIODevice::Unbuffered flag when you
>> setStandardOutputFile() in your sub-process?
>
> I do not usually use the setStandardOutputFile function because I
> would prefer to read the output myself and output it to a text
> editor in the parent process. However, I did just try to pass
> Unbuffered in as the open mode flag to QProcess::start when I start
> the sub-process, but this yielded no output except an error message
> "QIODevice: write only device".

Have you or'ed the flag? eg.: ReadWrite|Unbuffered

>
>> It is possible that the output buffer is flushed/drained only
>> when it reach a certain water mark level, in that case one
>> solution is to use unbuffered output (with potential penalty on
>> the performance), or flush/drain your output yourself.
>
> I am not real sure I understand what you mean by flush or drain the
> output myself. Any chance you could elaborate on this a little
> more?

I never use QProcess and I never had to do flush/drain with QT, but in 
the past I use to have to do this sort of things while coding "raw" C/C++.
Basically, flushing your output buffer means writing any unwritten data:
http://www.cplusplus.com/reference/clibrary/cstdio/fflush/

I used "flush/drain", because if you deal with serial ports (termios 
on unix/linux), flush means discarding data and drain mean "flush" as 
explained above.

Not sure if it is related, but your file Process1.txt is 4214 bytes 
long, and has 118 lines. note that 4*1024+118 = 4214 ...
Which could means that there's a 4Kb buffer and a CR=>CR+NL 
translation is happening somewhere...

Have you try to use read() instead?
http://doc.trolltech.com/4.7/qiodevice.html#read

This function at least return an error code, so it might help to 
pinpoint what's going on.
Something like this (not tested):

QByteArray data;
qint64 result;
char *buffer[1024];
while ((result = process.read(buffer, 1024) != 0) {
	if (result > 0)
		data.append(buffer, result)
	else if (result < 0)
		qDebug() << "Oops!!!";
}
qDebug() << data;

If it still not working, you will need to show us some code.

>
>>
>> Chris
>>
>> -- Christian Gagneraud, Electronics and software engineer
>>
>> TechWorks Marine Ltd 4a, Park Lane Dun Laoghaire, Co Dublin
>> Ireland
>>
>> Tel: + 353 1 2365990 Fax: + 353 1 2365992 Web: www.techworks.ie
>>
>>
>> _______________________________________________ Qt-interest
>> mailing list Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> _______________________________________________ Qt-interest mailing
> list Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest


-- 
Christian Gagneraud,
Electronics and software engineer

TechWorks Marine Ltd
4a, Park Lane
Dun Laoghaire, Co Dublin
Ireland

Tel: + 353 1 2365990
Fax: + 353 1 2365992
Web: www.techworks.ie





More information about the Qt-interest-old mailing list