[Interest] Read a binary file

Mehmet İpek mhmtipek at gmail.com
Wed Dec 19 21:40:59 CET 2012


I saw several issues in your Qt code.

* In native c code you read unsigned long (4 byte in 32 bit platforms) and
in Qt code you read quint64 (64 bit in all platforms).
* You are reading with readLine which if it sees an end of line char, it
stops reading. So, this is simply wrong. You have to use read(char * data,
qint64 maxSize) function defined in QIODevice(base of QFile).
* I see you are reading into a char array then give this array to
constructor of QByteArray. QByteArray will assume it is a str, which means
that makes a deep copy of char array until it sees a null char. This
probably causes problems.
* Reading into a char array, then making it QBuffer and reading QBuffer
with QDataStream is extra work. You can just open file and use QDataStream
with QFile. (sample codes exist in QDataStream documentation)
* And i couldn't see opening fData (like: fData->open(QIODevice::ReadOnly)).

On Wed, Dec 19, 2012 at 7:56 PM, Yuriy Rusinov <yrusinov at gmail.com> wrote:

> Hello, Syam !
>
> <syamcr at gmail.com> wrote:
> > On 12/19/2012 02:45 PM, Yuriy Rusinov wrote:
> >>      for (int i=1; i<=na; i++)
> >>      {
> >>          char * colData = new char [nd2*sizeof (unsigned long)];
> >>          qint64 colLength = fData->readLine (colData, nd2*sizeof
> >> (unsigned long));
> >
> > Why would you use readLine() for a binary file?
> > The concept of a 'line' is for text files. You should use read() instead.
>
> I tried it, but nothing changes.
>
>
> --
> Best regards,
> Sincerely yours,
> Yuriy Rusinov.
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121219/de95a715/attachment.html>


More information about the Interest mailing list