Adding image files to .qrc dynamically
-
I think that is not possible since the .qrc file is compiled and qrc_resourcesNameFile.cpp generated. This is the fail then added to the exec.
-
Hi,
I'm not sure I am following you.
Would you like that i.e. Qt creator to automatically append newly added images from a folder to a given qrc before building ?
-
Ok , if that is not possible i trying to read the contents of .qrc file using below approach.
my app is supposed to run on multiple platforms , will the following code portable or is there any stanadard way of extracting required files from .qrc.
@
QFile file("/home/wip/lays/images_QRC.qrc");
file.open(QIODevice::ReadOnly|QIODevice::Text);QTextStream in(&file); QString line = in.readLine(); while(!in.atEnd()){ if(line.contains("jpeg")||line.contains("png")){ // filters only images qDebug()<<"line 1 "<<line; QStringList line1 = line.split("<file>"); //removes " <file>" line = line1[1]; qDebug()<<"line 2 "<< line1[1]; QStringList line2 =line.split("</file>");//removes </file> line = line2[0]; qDebug()<<"line 3 "<<line; } line = in.readLine(); }
@
-
You'll have more chance of success reading the qrc file as xml. Your code assumes that tags and text are all on one line, which may not be the case.
-
There are no files to extract from the qrc file.
It's just an xml list of files on your system that rcc will transform to be compiled in your application, see the "rcc":http://qt-project.org/doc/qt-4.8/rcc.html doc
For more information there is the "resources":http://qt-project.org/doc/qt-4.8/resources.html documentation
Hope it helps
-
There is a much better way to generate to do this during the build process:
Make a template for Jinja (http://jinja.pocoo.org/), which is a python template interpreter:
resources.qrc
template:<!DOCTYPE RCC> <RCC version="1.0"> {% for key, value in input_files.items() -%} <qresource prefix="{{ key }}"> {%- for file in value %} <file>{{ file }}</file> {%- endfor %} </qresource> {% endfor -%} </RCC>
Main code for your Python script:
#!/usr/bin/env python from jinja2 import Environment, FileSystemLoader, select_autoescape import os from jinja2 import Environment, FileSystemLoader, select_autoescape env = Environment(loader=FileSystemLoader(options.templates), autoescape=select_autoescape(['qrc'])) template = env.get_template('resources.qrc') input_files = [] for root, dirs, files in os.walk(path_with_input_files): for file in files: input_files += file with open(output.qrc, "w") as resource_file: resource_file.write(template.render(input_files=input_files))
This will generate a new
output.qrc
file with the files frompath_with_input_files
! ;-)