2012/01/03

SCons and Qt Resource files

Today I've stumbled upon a bug/problem with SCons' support for Qt resource files (the ones with QRC extension).
Usually, to add a QRC to your project you add a line like this:
qrcobj = programEnv.Qrc("SomeFile.qrc", QT4_QRCFLAGS="-name SomeFile")
and all is well.
But - probably due to a bug somewhere in qt4.py module, the files that are referenced from inside the QRC (the actual images and stylesheets) are not added as a dependency to the build process, so when you change a CSS file, the QRC will not be rebuilt.
The snippet below parses the QRC manually, fetches the list of files inside and adds the to deps list; Python rocks.


#adding qrc resources compilation
import xml.dom.minidom
qtResourceFile = []
for q in ("GUI.qrc", "UI/UI.qrc",):
baseq = os.path.basename(q)[:-4]
qrcdeps = []
qrc = programEnv['ENV']['PWD'] + "/GUI/" + q
dir = os.path.dirname(qrc)
x = xml.dom.minidom.parse(open(qrc))
for filenode in x.getElementsByTagName("file"):
qrcdeps += [ dir + "/" + filenode.childNodes[0].data ]
qrcobj = programEnv.Qrc(q, QT4_QRCFLAGS="-name "+baseq)
programEnv.Depends(qrcobj, qrcdeps)
qtResourceFile += [ qrcobj ]

No comments:

Post a Comment