Results 1 to 4 of 4

Thread: Binary file in QTextEdit

  1. #1
    Join Date
    Oct 2010
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Binary file in QTextEdit

    I would like to display binary file in QTextEdit but cannot find the right way to do so. I am trying to load the file and display its whole content. I have tried to load file's content as QTextStream, QDataStream and ByteArray but nothing let me display the file correctly...seems to me that problem is in QString.
    - setText method seems to accept only QString (some automatic conversions seems to be possible)
    - when setText displays QString, it finishes when it reaches byte 00 which represents \0 (null termination) thus I can see only first few bytes before first 00

    Do you guys know any efficient and easy way how to solve it? Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Binary file in QTextEdit

    Please define:
    "display a binary file"

    Is this:
    1. A text file binary encoded that you want to decode and display as a normal text?
    2. A binary file that you want to display as hexadecimal numbers?

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Binary file in QTextEdit

    Maybe the QHexEdit is a solution for You.

  4. #4
    Join Date
    Oct 2010
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Binary file in QTextEdit

    Quote Originally Posted by tbscope View Post
    Please define:
    "display a binary file"

    Is this:
    1. A text file binary encoded that you want to decode and display as a normal text?
    2. A binary file that you want to display as hexadecimal numbers?
    its a binary file like PE files (.exe, .dll,...), c++ object files (.o), ELF files, etc... and I would like to display it in some suitable coding like hex editors usually do (when you see hex representation of bytes in the one column and characters representation in another column. Exactly as shown for example here:
    http://commons.wikimedia.org/wiki/File:Hiew-hex.jpeg
    - but I am not interested in hex representation right now...just would like to put characters as seen in the right part of the screenshot to the TextEdit.

    Seems I need to find suitable coding and convert whole ByteArray before printing. Do you have any experience with this?

    Thanks for QHexEdit...I will take a look and maybe I can get something from it.

Similar Threads

  1. Read binary file
    By jaca in forum Qt Programming
    Replies: 9
    Last Post: 28th March 2012, 08:38
  2. File Editing (Binary/Hex) with Qt 4.6.2
    By RH-00 in forum Qt Programming
    Replies: 3
    Last Post: 8th October 2010, 20:58
  3. cannot execute binary file
    By mgturner in forum Installation and Deployment
    Replies: 1
    Last Post: 16th March 2009, 17:04
  4. How to Print a doc file (or binary file) to printer
    By rmagro in forum Qt Programming
    Replies: 15
    Last Post: 5th September 2008, 15:46
  5. binary file sending using qt4.3
    By omprakash in forum Qt Programming
    Replies: 3
    Last Post: 22nd May 2008, 20:56

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.