[Qt-interest] Problem with sending binary data to stdin of QProcess child. There's no QProcess::flush
Scott Aron Bloom
Scott.Bloom at sabgroup.com
Mon Jan 12 08:27:15 CET 2009
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Bart van Deenen
> Sent: Sunday, January 11, 2009 11:11 PM
> Cc: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] Problem with sending binary data to stdin of
> QProcess child. There's no QProcess::flush
>
> On Sun, 2009-01-11 at 19:59 +0100, Andreas Pakulat wrote:
> > On 11.01.09 19:36:10, Bart van Deenen wrote:
> > > On Sunday 11 January 2009 16:12:57 Andreas Pakulat wrote:
> > > > On 10.01.09 13:16:27, Bart van Deenen wrote:
> > >
> > > > > I'm stuck with getting data from the parent process to the child
> process
> > > > > though, and I don't see where I'm going wrong.
> > > > > qint64 ct = process.write(s.data(), s.length());
> > > > > the std::string s is a google protocol buffer encoded string, i.e.
> > > > > binary blobs. The current test message has a length of 2 bytes, and I
> > > > > always receive the message "Wrote 2 bytes to child process" so that
> goes
> > > > > well.
> > > > >
> > > > > On the child receiver side I have a QThread, that should handle the
> > > > > commands on stdin,
> > > > > but It always tells me that there is no data available. ('debug' is a
> > > > > member QFile * for debugging purposes). I've also tried
> f.open(stdin,...)
> > > > > and std::cin and you name it.
> > >
> > > > Well, you're not closing or flushing stdin of the process, so the data
> > > > might still be in some buffer (Qt or native). So if you don't need stdin
> > > > anymore, just close it on the sender side. Else at least flush it after
> > > > you've written your chunk of data.
> > >
> > > But how??
> > >
> > > There is no flush() for QProcess, even though QIODevice defines a flush.
> >
> > QProcess is a QIODevice, so you can just call flush() on your process,
> > that should work.
> That's what I would think, but just try it:
>
> #include <QtCore/QCoreApplication>
> #include <QProcess>
> int main(int argc, char *argv[]) {
>
> QCoreApplication a(argc, argv);
> QProcess process;
> process.flush();
> return a.exec();
> }
>
> make[1]: Entering directory `/home/bvandeenen/qprocess-flush-test'
>
> g++ -c -pipe -g -Wall -W -D_REENTRANT -DQT_CORE_LIB -DQT_SHARED
> -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore
> -I/usr/include/qt4/QtCore -I/usr/include/qt4 -Idebug -I. -o debug/main.o
> main.cpp
>
> main.cpp: In function ‘int main(int, char**)’:
> main.cpp:7: error: ‘class QProcess’ has no member named ‘flush’
> make[1]: Leaving directory `/home/bvandeenen/qprocess-flush-test'
>
>
> This sucks
>
> Thanks for thinking along
>
> Bart
Have you tried setting it to unbuffered using setOpenMode ?
There is no flush for QProcess or QIODevice... But setting its mode to unbuffered should clear things up.
Scott
More information about the Qt-interest-old
mailing list