Results 1 to 2 of 2

Thread: Reading binary data

  1. #1
    Join Date
    Sep 2006
    Posts
    339
    Thanks
    15
    Thanked 21 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Reading binary data

    Hi guys,
    Please help me to read the attached binary file "exactly" to some other file.
    The copied file has to be same.
    Here is the code that I use. But the copied file is modified.

    Qt Code:
    1. QString message;
    2. QFile f ( "m1_enc.ct" );
    3. if ( f.open (IO_ReadOnly) )
    4. {
    5. // file opened successfully
    6. QDataStream t ( &f );
    7. // read the contents of the file into message
    8. char* m = new char[f.size() +1];
    9. t.readRawBytes ( m, f.size() );
    10. message = m;
    11. f.close();
    12. }
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QFile f ( "copied_file_enc.ct" );
    2. if ( f.open (IO_WriteOnly) )
    3. {
    4. // file opened successfully
    5. QDataStream t ( &f );
    6. // read the contents of the file into message
    7. t << message;
    8. }
    9. f.close();
    To copy to clipboard, switch view to plain text mode 

    In my case the copied_file_enc.ct is modified.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reading binary data

    Qt Code:
    1. QFile f("input");
    2. f.open(QFile::ReadOnly);
    3.  
    4. QFile f2("ouptut");
    5. f2.open(QFile::WriteOnly|QFile::Truncate);
    6.  
    7. QByteArray dat = f.readAll();
    8. f2.write(dat);
    9. f.close();
    10. f2.close();
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to wysota for this useful post:

    vermarajeev (13th August 2007)

Similar Threads

  1. problem with reading input data in qt
    By Ahmad in forum Qt Programming
    Replies: 3
    Last Post: 9th April 2007, 10:58
  2. reading DVD data and mpeg2 streams
    By guestgulkan in forum General Programming
    Replies: 1
    Last Post: 18th February 2007, 22:24
  3. reading and writing data from a QTableWidget
    By zorro68 in forum Qt Programming
    Replies: 4
    Last Post: 29th January 2007, 20:51
  4. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  5. How to convert binary data to hexadecimal data
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 8th March 2006, 16:17

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.