Reading files from resources
-
Hello!
I am trying to load a template from resources make a docx file (using docx factory lib). If I copy the template in the program folder, it reads successfully but, when I try to read it from resources, it can't read it.
I have the same problem when I try to add an image in this docx. Is it possible to read this kind of files from the resources?
/** TEMPLATE **/ QString sTemplatePath = QApplication::applicationDirPath() + "/template.dfw"; // works fine QString sTemplatePath = ":/templates/resources/templates/template.dfw" // can't read the file l_merger.load(sTemplatePath.toStdString()); ... /** IMAGES **/ sImagePath = QCoreApplication::applicationDirPath() + "/image.png"; // works fine sImagePath = ":/images/resources/images/image.png"; // can't read the file l_merger.setClipboardValue("Header", "Image", sImagePath.toStdString()); l_merger.paste("Header"); ...
Thank you very much!
-
Hi,
Do you have that folder structure in your resources ?
-
See this:
@ivanicy said in Reading files from resources:
l_merger.load(sTemplatePath.toStdString());
Looks like
l_merger
is not a Qt class, is it ? If so, then it won't be able to read from the resources because it has not idea on how to access it.In that case, you should create a temporary file, pass the path l_merger and continue processing.