PDA

View Full Version : Binary file in QTextEdit



xproch13
28th October 2010, 17:34
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

tbscope
28th October 2010, 17:44
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?

Lesiok
28th October 2010, 19:29
Maybe the QHexEdit (http://qt-apps.org/content/show.php/QHexEdit?content=133189&PHPSESSID=b670e06b25b7fab68abe966de8a4b8ae) is a solution for You.

xproch13
28th October 2010, 21:07
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.