8

I'm trying to understand an example in PyQt4 (simpletreemodel.pyw) I see the code

import simpletreemodel_rc

But I can't see where the module is used in the example code When I examine the module simpletreemodel, I see:

    from PyQt4 import QtCore

qt_resource_data = b"\
\x00\x00\x07\xb9\
\x47\
\x65\x74\x74\x69\x6e\x67\x20\x53\x74\x61\x72\x74\x65\x64\x09\x09\
\x09\x09\x48\x6f\x77\x20\x74\x6f\x20\x66\x61\x6d\x69\x6c\x69\x61\
\x72\x69\x7a\x65\x20\x79\x6f\x75\x72\x73\x65\x6c\x66\x20\x77\x69\
\x74\x68\x20\x51\x74\x20\x44\x65\x73\x69\x67\x6e\x65\x72\x0a\x20\
\x20\x20\x20\x4c\x61\x75\x6e\x63\x68\x69\x6e\x67\x20\x44\x65\x73\
\x69\x67\x6e\x65\x72\x09\x09\x09\x52\x75\x6e\x6e\x69\x6e\x67\x20\
\x74\x68\x65\x20\x51\x74\x20\x44\x65\x73\x69\x67\x6e\x65\x72\x20\

What this module is supposed to do? Thanks

nam
  • 3,542
  • 9
  • 46
  • 68

1 Answers1

14

What you see is the byte-by-byte dump of the resources the .qrc file contains. You don't explicitly access the objects inside the module. Just import it, and you will be able to access those resources by their original names(and paths) but preceded by a colon.

pixmap = QPixMap(':/images/filename.jpg')

UPDATE: QRC file is an XML file that looks like below:

<RCC>
  <qresource prefix="/images">
    <file alias='filename.jpg'>images/filename.jpg</file>
  </qresource>
</RCC>

Then to generate it, use:

pyrcc4 -o images_rc.py images.qrc
UltraInstinct
  • 43,308
  • 12
  • 81
  • 104
  • Is the module generated automatically by Python? and how to create the qrc file? – nam Jun 08 '12 at 16:26
  • But can you explain why we need to generate the images_rc.py instead of using directly the image file? Is it a performance optimization? – nam Jun 09 '12 at 22:06
  • 3
    Its optional. Its like we are 'embedding' the image bytes in the application itself, rather than reading from the disk. – UltraInstinct Jun 10 '12 at 03:18