[PySide] Help with resource files
Sean Fisk
sean at seanfisk.com
Sat Apr 6 23:51:28 CEST 2013
Hello everyone,
I want to embed some images and fonts in my PySide program using Qt's resource system. I've used it very successfully in C++. However, I'm having some trouble getting resource files to work with PySide. The resource files seem to compile it all right, but I can't read my files in my program.
I've created a minimum example to illustrate the problem:
test.py
#!/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.QFile(':/test.txt') print 'Does it exist?: {0}'.format(test_txt.exists()) print "readAll(): `{0}'".format(test_txt.readAll())
resources.qrc
<RCC> <qresource prefix="/"> <file>test.txt</file> </qresource> </RCC>
test.txt
This is just a test.
Instructions
Compile the resource file and then run:
$ pyside-rcc resources.qrc -o resources.py $ python test.py Running PySide 1.1.2 / Qt 4.8.4 PySide compiled with Qt 4.8.4 Does it exist?: True readAll(): `'
Interestingly, if I change the readAll() call to readLine(), the program segfaults. Anyone have any suggestions? I'd be open to other ways to distribute fonts and images with my program as well.
Sincerely,
--
Sean Fisk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20130406/4db20f38/attachment.html>
More information about the PySide
mailing list