[PyQt] binary file viewer with textEdit (PyQt) [correction]

Mark Summerfield list at qtrac.plus.com
Thu Jun 24 13:21:21 BST 2010


[snip]

Actually I meant:

    file = QFile(self.filename)
    if file.open(QIODevice::ReadOnly):
	ba = file.readAll() # ba is a QByteArray filled with raw bytes
	hexbytes = []
	for i in range(ba.count()):
	    if QChar(" ") < QChar(ba[i]) < QChar(128):
		hexbytes.append(ba[i].toAscii())
	    else:
		hexbytes.append(ba[i].toHex()) 
		# the above might need to be:
		# hexbytes.append(QByteArray(ba[i]).toHex())
		# or even:
		# hexbytes.append(str(QByteArray(ba[i]).toHex()))
	self.ui.textEditAscii1.setPlainText("".join(hexbytes))


Still untested though!

-- 
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
    C++, Python, Qt, PyQt - training and consultancy
        "Rapid GUI Programming with Python and Qt" - ISBN 0132354187
            http://www.qtrac.eu/pyqtbook.html


More information about the PyQt mailing list