[PyQt] PyQt4 Python File Object to QFile

Russell Valentine russ at coldstonelabs.org
Fri Feb 12 19:39:34 GMT 2010

David Boddie wrote:
> On Fri Feb 12 06:55:21 GMT 2010, Russell Valentine wrote:
>> 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.
> [...]
>> 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.
> qt_
> Try this:
>   f = open(...)
>   qt_f = QFile()
>   qt_f.open(f.fileno(), QFile.ReadOnly)
> http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qfile.html#open-2

Thank you for your reply. I had thought that there are some non-posix 
systems where fileno doesn't work. I tried it in Linux and Windows. 
Seems to work in Linux, but not in Windows. So it looks like it is a 
good solution for posix systems at least.

Russell Valentine

More information about the PyQt mailing list