Results 1 to 12 of 12

Thread: Binary file Reading.........

  1. #1
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Binary file Reading.........

    Hai


    I have a binary file I want to read that

    either I have to use QBitArray or ByteArray ... DataStream

    pl help me

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Binary file Reading.........

    If you want to access data bit by bit. For various binary operations. You should use QBitArray.
    Otherwise QByteArray and QDataStream will work.

  3. #3
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Binary file Reading.........

    Hai

    that binary file in LittleEndian format

    what to do?

    pl give some example..

  4. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Binary file Reading.........

    Quote Originally Posted by umulingu View Post
    Hai
    that binary file in LittleEndian format
    The QDataStream class provides serialization of binary data to a QIODevice.
    A data stream is a binary stream of encoded information which is 100% independent of the host computer's operating system, CPU or byte order


    Quote Originally Posted by umulingu View Post
    pl give some example..
    Qt Code:
    1. QFile file("file.dat");
    2. file.open(QIODevice::ReadOnly);
    3. QDataStream in(&file); // read the data serialized from the file
    4. QString str;
    5. qint32 a;
    6. in >> str >> a; // extract "the answer is" and 42
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Binary file Reading.........

    hai

    i tried with QDataStream and QByteArray. but the data is empty...


    Qt Code:
    1. QFile fileA("/home/suresh/file1.lnd");
    2. QByteArray buffer;
    3. if(! fileA.open(QIODevice::ReadOnly))
    4. {
    5. QMessageBox::information(this,tr("Unable to Open"),fileA.errorString());
    6. return;
    7. }
    8. buffer=fileA.readAll();
    9. qDebug()<<buffer.data();
    10. qDebug()<<buffer.size();
    To copy to clipboard, switch view to plain text mode 



    output

    

    206368
    Last edited by wysota; 17th July 2009 at 20:10. Reason: missing [code] tags

  6. #6
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Binary file Reading.........

    dont use buffer.data() in qDebug... just use buffer... because a zero may terminate the char* at any point..

  7. #7
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Binary file Reading.........

    Quote Originally Posted by umulingu View Post
    qDebug()<<buffer.data();
    qDebug()<<buffer.size();


    output
    206368
    The data is in the buffer, its just not printed by qDebug. You can write this buffer in another file and see. Both files should be identical.

  8. #8
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Binary file Reading.........

    Hai
    thanks for ur reply

    actually that is binary file .
    I want to read the data

    how to get the datas?

  9. #9
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Binary file Reading.........

    every binary file has a format... do you have the format (struct etc)..?

  10. #10
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Binary file Reading.........

    yes I have that program and format

  11. #11
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Binary file Reading.........

    then just go simple.. nad read the data as it was written in that program..

    it must be written as
    FILE* fp
    fwrite(struct* ,fp);

    so read it that way only..
    FILE* fp
    fread();...

  12. #12
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Binary file Reading.........

    Thanks to all


    I got solution.

Similar Threads

  1. reading 4-bytes integer from binary file
    By maka in forum Qt Programming
    Replies: 8
    Last Post: 12th May 2009, 05:57
  2. Read binary from file
    By weldpua2008 in forum Newbie
    Replies: 2
    Last Post: 3rd April 2009, 23:50
  3. cannot execute binary file
    By mgturner in forum Installation and Deployment
    Replies: 1
    Last Post: 16th March 2009, 17:04
  4. Reading binary data
    By vermarajeev in forum Qt Programming
    Replies: 1
    Last Post: 13th August 2007, 09:14
  5. Sending Binary File with QFTP
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 7th March 2007, 18:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.