[PySide] Help with resource files

Algis Kabaila akabaila at pcug.org.au
Sun Apr 7 08:14:52 CEST 2013


Hello Sean,

It is not a fault of python version.  I am on linux kubuntu 12.04 LTS OS 
with "python" pointing to python 2.7  and python3 to python 3.2.  Changed 
your script to python3 syntax and repeated the exercise with the same 
lemon result at the end:

ak at supremo:~/Documents/2013/Algis/linux$ python3 test.py
Running PySide 1.1.0 / Qt 4.8.1
PySide compiled with Qt 4.8.1
Does it exist?: True
readAll(): `'
ak at supremo:~/Documents/2013/Algis/linux$ 

"supremo" is a funny name for my old black big and clunky computer (with a 
decent PCU etc.) 

There is a small reference to accessing files in Mark Summerfields "bible" 
on PyQt.  But now I must quit this keyboard - one of our grand daughters 
is comming to watch a film on Lithuanian basketball, named "the other dream 
team".

Sorry for butting in to the list - hope to be back sometime and might try 
to concoct my own example and see if it shows where the "dog is burried".

Al.

On Sunday 07 April 2013 01:27:24 Sean Fisk wrote:

                    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/f32a6be1/attachment.html>


More information about the PySide mailing list