Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Reading files from resources
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!
Do you have that folder structure in your resources ?
Yes, when I want to use this images for example in the stylesheet it works fine.
And you find the DFW file in the explorer tree under ressources
and right click and take path via menu so you are 10000% sure its correct path ?
I took this path rightclicking on the resources file and selecting "Copy Path" option so the path is correct. I try with the "Copy URL" option too but with the same result.
If I set a QPushButton icon with this paths, it works.
But are you pasting it directly to the clipboard ?
So when other app reads/see it,
it will be the resource path which only a Qt app can understand ?
l_mergeris 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.
@SGaist Yes, I think this could be the problem. It is a third party library so, maybe what is happening herer is what you say. I get the same error trying to use this image with opencv.
Yes, only QFile understands resources so if openCV uses normal file functions , it cannot load it.
You have to save to a real file first then and use that path.