OK, I have an interim solution. While I do believe that QFile.readAll() should return the file contents as a QByteArray, QResource.data() seems to work! Here is the code:
#!/usr/bin/env python # test.py import PySide from PySide import QtCore import resources
# Versions print 'Running PySide {0} / Qt {1}'.format( PySide.__version__, QtCore.__version__) print 'PySide compiled with Qt {0}'.format(QtCore.qVersion()) # Read resource test_txt = QtCore.QResource(':/test.txt') data = test_txt.data() print "type(data()): {0}".format(type(data)) print "data(): `{0}'".format(data)
which yields
Running PySide 1.1.2 / Qt 4.8.4 PySide compiled with Qt 4.8.4 type(data()): <type 'buffer'> data(): `This is just a test. '
This returns the resource as a Python buffer type. I'm hoping I can coerce this into the source for a font or image in Qt.
More updates if I get it to work.
Sincerely,
--
Sean Fisk
On Monday, April 8, 2013 at 4:41 PM, Sean Fisk wrote:
That's good to know, Eric. Eventually we will be doing Windows distribution so I'm glad there are no problems.Here is another update. I tried putting Lena on a button using QIcon on my OS X installation and it worked:
That leads me to believe it's a problem with QFile, not the actual generated resource file. I'm going to try messing around with the QResource class next.Thanks for all the help, guys!Sincerely,--Sean FiskOn Monday, April 8, 2013 at 3:18 PM, Eric Johnson wrote:
Sean Fisk <sean <at> seanfisk.com> writes:Thanks for the confirmation with Python 2 and 3 on Ubuntu. Although wedon't yet know whether it is a bug or just incorrect code by me.Works fine for me on Windows (cygwin/bash shell but win32 version ofPython 2.7.2) if I open the file first.I'm surprised there is no exception thrown if you don't do this.I can try on OS X tonight....# Read resourcetest_txt = QtCore.QFile(':/test.txt')test_txt.open(QtCore.QIODevice.ReadOnly | QtCore.QIODevice.Text)print 'Does it exist?: {0}'.format(test_txt.exists())print "readAll(): `{0}'".format(test_txt.readAll())gives output$ python test.pyRunning PySide 1.1.0 / Qt 4.7.4PySide compiled with Qt 4.7.4Does it exist?: TruereadAll(): `This is just a test.'Eric_______________________________________________PySide mailing list
_______________________________________________ PySide mailing list [email protected] http://lists.qt-project.org/mailman/listinfo/pyside
