Results 1 to 20 of 28

Thread: Binary files and conversion

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,375
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Binary files and conversion

    Quote Originally Posted by timmu View Post
    How would you recommend to read the file?
    With QFile and its QIODevice API.

    What I understand is that you simply want a hex dump of the file. The most trivial approach (albeit far from optimal in terms of memory) is:

    Qt Code:
    1. QFile in("infile");
    2. QFile out("outfile");
    3. in.open(QIODevice::ReadOnly);
    4. out.open(QIODevice::WriteOnly);
    5. out.write(in.readAll().toHex());
    To copy to clipboard, switch view to plain text mode 

    You can do the same if you want a decimal encoding, only that you need to iterate over each byte in the array and convert it manually to a decimal value.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    timmu (27th November 2012)

Similar Threads

  1. How to write and read from binary files
    By Momergil in forum Newbie
    Replies: 9
    Last Post: 28th November 2011, 12:58
  2. integrated + binary resource files
    By Le_B in forum Qt Quick
    Replies: 0
    Last Post: 5th June 2011, 17:45
  3. Reading Binary Files
    By archanasubodh in forum Newbie
    Replies: 1
    Last Post: 27th February 2008, 13:31
  4. How can I read Binary files with Qt
    By geo_saleh in forum Qt Programming
    Replies: 2
    Last Post: 16th August 2007, 11:37
  5. Concatenating two binary files
    By nbkhwjm in forum Newbie
    Replies: 13
    Last Post: 23rd April 2007, 04:30

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
  •  
Qt is a trademark of The Qt Company.