KProcess Line Mode Patch

Thiago Macieira thiago at kde.org
Tue Dec 2 14:59:08 GMT 2008


On Tuesday 02 December 2008 14:23:51 Andreas Pakulat wrote:
> > +qint64 KLineBasedReader::readLine(char * data, qint64 maxSize)
> > +{
> > +    qint64 ret = m_p->readLine(data, maxSize);
> > +    if (ret <= 0)
> > +        return ret;
> > +    if (data[strlen(data)-2] == '\x0d' && data[strlen(data)-1] ==
> > '\x0a')
>
> That won't happen, QIODevice will already replace windows line-endings with
> unix-ones (unless you don't use QIODevice::Text, in which case you
> shouldn't be reading lines).

I'd say leave it, since the device may be open already in binary mode.

>
> > +        data[strlen(data)-2] = '\0';
> > +    else if (data[strlen(data)-1] == '\x0a')
> > +        data[strlen(data)-1] = '\0';
> > +    return ret;
> > +}

Also, please remember to reduce the value of ret to the number of characters 
you removed.

Another thing: the signal readyReadLine() is emitted every time new data 
arrives, as long as there's one full line. Is that what you intended? If so, 
then I make Andreas's comment my own:

> With the above changes, what exactly is the benefit of this class? IMHO it
> doesn't provide any real value compared to listening for the readyRead()
> signal from QIODevice+checking for canReadLine and then reading the line
> into a char* or even a QByteArray.

What would be useful, though, would be if this signal were emitted every time 
a new, full line were available. So, if it emits twice, we should be able to 
read two lines without error.

In addition, it seemed that the API that people wanted was a QList<QByteArray> 
for all lines.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Software Engineer - Nokia, Qt Software
  Qt Software is hiring - ask me
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20081202/3727a6b1/attachment.sig>


More information about the kde-core-devel mailing list