[PyQt] PyQt4 Python File Object to QFile
Russell Valentine
russ at coldstonelabs.org
Fri Feb 12 06:55:21 GMT 2010
I wonder if anyone ever bridged the gap between QFile and the Python
File Object? It could be handy sometimes to go between the two.
The only way that comes to my head right now is to reimplment QFile or
QIODevice, so it would use a python file object for all it's io. That
seems a bit messy so I thought I'd ask if there was something I was missing.
class QPythonFile(QFile)
..reimplement almost all of QFile functions to use python object with
a constructor that also can take a python file object...
def getPythonOjbect(self): #Returns the python file object.
You might wonder when this would ever be needed.
How about for example if I wanted to open a file from a zip file.
zfile = zipfile.ZipFile("test.zip")
f=zfile.open("some.png", 'r')
qtf = QPythonFile(f)
img=QImage()
img.load(qtf)
pixmap=QPixmap.fromImage(img)
f is a python file object but, how can I use this in Qt? I realize I
could save it to some temp file and reopen it with QFile but that seems
unelegant.
Russell Valentine
More information about the PyQt
mailing list