[PySide] Help with resource files
Sean Fisk
sean at seanfisk.com
Sun Apr 7 07:27:24 CEST 2013
Hello Al,
My bad. I'm using Python 2.7.3 64-bit on Mac OS 10.6 with PySide 1.1.2 and Qt 4.8.4. It's not the system Python nor one installed from the distributions on python.org; I compiled it myself and am using virtualenvwrapper to manage my virtualenvs, if any of that matters.
Thanks for the tip on Python 3. I'm using Python 2 and I believe that pyside-rcc defaults to Python 2. The resource module is in fact importing fine. There are no syntax errors or anything like that. It's weird: I tried importing in ipython and the import was fine. I just can't read the resource content as I should be able to.
Thanks,
--
Sean Fisk
On Sunday, April 7, 2013 at 1:19 AM, Algis Kabaila wrote:
>
> Hi Sean,
>
>
>
>
>
> You do not give much away: to begin with, your OS and Python version would be useful.
>
>
>
>
>
> If it is Python 3.x then a small change may help:
>
>
>
>
>
> pyside-rcc -py3 resources.qrc -o resources.py
>
>
>
>
>
> Just a shot in the dark, Sean!
>
>
>
>
>
> Al.
>
>
>
>
>
> On Saturday 06 April 2013 17:51:28 Sean Fisk wrote:
>
>
>
> 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/20130407/d4a1d564/attachment.html>
More information about the PySide
mailing list