+ Reply to Thread
Results 1 to 3 of 3

Thread: i write a test program whit QDatastream read and write the binary file but it's dif

  1. #1
    Join Date
    Apr 2009
    Posts
    29
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Android

    Default i write a test program whit QDatastream read and write the binary file but it's dif

    i write a test program whit QDatastream
    read and write the binary file
    but
    it's different

    my code
    Qt Code:
    1. QFile file("1.png");
    2. file.open(QIODevice::ReadOnly);
    3. QFile tmp("2");
    4. tmp.open(QIODevice::WriteOnly);
    5. QDataStream out(&tmp);
    6. out << file.readAll();
    To copy to clipboard, switch view to plain text mode 

    diff 1.png 2
    output:
    Binary files 1.png and 2 differ
    why ?
    Last edited by Lykurg; 2nd November 2010 at 06:21. Reason: changed [qtclass] to [code]

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    6,405
    Thanks
    13
    Thanked 1,353 Times in 1,295 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: i write a test program whit QDatastream read and write the binary file but it's

    They differ because a QDataStream is not a raw byte stream. You call QIODevice::readAll(), which returns a QByteArray, and then ask QDataStream to serialise the QByteArray to a stream. QDataStream will output sufficient information to reconstruct the QByteArray, including any internal structures, by reading from QDataStream later on any platform. You really just want the base QIODevice methods to read and write raw bytes.

    If you just want to copy a file then QFile::copy() will be of interest.

  3. #3
    Join Date
    Apr 2009
    Posts
    29
    Thanks
    7
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Android

    Default Re: i write a test program whit QDatastream read and write the binary file but it's

    what you have said is very helpful, thank you very much, ChrisW67.

+ Reply to Thread

Similar Threads

  1. QFile - QDataStream read and write each character
    By nhs_0702 in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2010, 19:03
  2. How to write a QList into a binary file?
    By Lawand in forum Qt Programming
    Replies: 23
    Last Post: 15th June 2009, 10:04
  3. file read & write help....
    By aj2903 in forum Qt Programming
    Replies: 1
    Last Post: 17th November 2008, 11:58
  4. [Java] read and write a file
    By mickey in forum General Programming
    Replies: 3
    Last Post: 22nd June 2008, 10:43
  5. How to read/write sets of orderded numbers in binary
    By kaydknight in forum General Programming
    Replies: 3
    Last Post: 12th March 2007, 05:50

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