[Qt-interest] [SOLVED] Does QProcess::readAllStandardOutput have a limit?
Eric Clark
eclark at ara.com
Fri Dec 3 01:53:59 CET 2010
> -----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 3:21 PM
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] Does QProcess::readAllStandardOutput have a
> limit?
>
> 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
I am sorry about that, I did not realize that the function took an instance of QFlags, I thought it was just one possible value. However, this did not work either.
>
> >
> >> 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;
I tried read as well and this gave me the same result. Thank you for the code example and explanation though. I actually do know what it means to flush the stream, but I was confused as to how to do it from the parent process. I was thinking that I needed to flush the sub-process' stream via the parent process and that was the wrong thing to think. Instead, I think you were suggesting that I flush the stream from within the sub-process' code. It is a little confusing because both the parent and sub are the same application. However, I did go to the printf statement that is used to output from the application and changed it to a fputs with a fflush immediately after. This solved my problem. I just needed to flush the output stream after I wrote to it. Now, everything works great! I really appreciate all of the help that everyone gave me.
Thank You!
Eric
>
> 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
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list