Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, August 2007
Reading QProcess output unbuffered


Message 1 in thread

Hi all,

I'm having a little problem here that I haven't been able to solve. I
have a QProcess connected with some slots to read its output like
this:

    m_ffmpeg = new QProcess;
    m_ffmpeg->setProcessChannelMode(QProcess::MergedChannels);
    m_ffmpeg->setWorkingDirectory(QDir::temp().absolutePath());


    connect(m_ffmpeg, SIGNAL(readyReadStandardError()), this,
SLOT(readOutput()));
    connect(m_ffmpeg, SIGNAL(readyReadStandardOutput()), this,
SLOT(readOutput()));
    connect(m_ffmpeg, SIGNAL(readyRead()), this, SLOT(readOutput()));

The problem is (as you may know if you've ever worked with ffmpeg in
command line) that the process output prints the information lines in
stderr using a \r character instead of a \n one.

The signals are correctly emitten in both QT Linux and QT Mac, and I'm
able to read the data in the slot methods, but for some reason I don't
know the signals are not emitted in QT Windows. I guess it might be
something about the stderr not being buffered or windows treating \r
differently than the unix systems.

I need to read the process output to give the user a feedback on the
process completion percentage, because sometimes it takes a long time
and it may seem that the program just freezed if I give no feedback.

I also tried to redirect the output to a file and adding the signals
to the file instead of the output buffer directly, but it didn't work
either.

Any suggestions I may try before giving up?

Thanks!

-- 
 [ signature omitted ] 

Message 2 in thread

My experience is: 1) the readyReadStandardError is always emitted
because os does not buffer stderr; 2) the readyReadStandardOutput is
emitted only after the os stdout buffer (e.g. 4096b) is filled or
the process finish. I looked at the qprocess.cpp, it is not obvious
how to flush the stdout buffer.

> Hi all,
>
> I'm having a little problem here that I haven't been able to solve. I
> have a QProcess connected with some slots to read its output like
> this:
>
>     m_ffmpeg = new QProcess;
>     m_ffmpeg->setProcessChannelMode(QProcess::MergedChannels);
>     m_ffmpeg->setWorkingDirectory(QDir::temp().absolutePath());
>
>
>     connect(m_ffmpeg, SIGNAL(readyReadStandardError()), this,
> SLOT(readOutput()));
>     connect(m_ffmpeg, SIGNAL(readyReadStandardOutput()), this,
> SLOT(readOutput()));
>     connect(m_ffmpeg, SIGNAL(readyRead()), this, SLOT(readOutput()));
>
> The problem is (as you may know if you've ever worked with ffmpeg in
> command line) that the process output prints the information lines in
> stderr using a \r character instead of a \n one.
>
> The signals are correctly emitten in both QT Linux and QT Mac, and I'm
> able to read the data in the slot methods, but for some reason I don't
> know the signals are not emitted in QT Windows. I guess it might be
> something about the stderr not being buffered or windows treating \r
> differently than the unix systems.
>
> I need to read the process output to give the user a feedback on the
> process completion percentage, because sometimes it takes a long time
> and it may seem that the program just freezed if I give no feedback.
>
> I also tried to redirect the output to a file and adding the signals
> to the file instead of the output buffer directly, but it didn't work
> either.
>
> Any suggestions I may try before giving up?
>
> Thanks!
>
> --
> Live long and prosper
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>


-- 
 [ signature omitted ]