[Solved] Qt Ressource from ABOVE directory
Hi everyone, nice appearance of the new system, I need some time to get to know the new structure though. ;)
Nevertheless, questions about Qt still remain... In my application I need to use ressources. I have boiled down the problem a little bit and came to this: I use an icon from a directory that is child to the application's source directory. I have added it using the Qt Creator 3.1.1 to the "Ressourcendateien" .qrc file. When I look into the physical file it reports - among others - it like this: "<file>ServiceTools_Shared_QT/Standard/SennLogo.ico</file>" which is fine. The path I use to access the ressource in my program reads ":ServiceTools_Shared_QT/Standard/SennLogo.ico", seems to fit and everything works fine.
However, due to the structure of my projects, this is a shared ressource, so I would like to use it from a directory that is NOT a child to the application's source. So the new path would be "<file>../ServiceTools_Shared_QT/Standard/SennLogo.ico</file>" and the file I use to access it in my source would change to "../ServiceTools_Shared_QT/Standard/SennLogo.ico" to keep the analogy. Unfortunately - without changing anything else - the icon will not be loaded when starting the application.
Can you confirm that ressources have to be stored as a child to the application's source?
I suppose it's correctly included by the linker(?), but can't be referred by something like ":../"?
May there be a different way to get access to this ressource?
A share of your experiences would be much appreciated, thanks in advance.
Resources do not have to be in a child directory.
I don't know if it's intended or a bug but you indeed can't access these resources with a path with "..".
What you can do though is give it an alias, e.g.:
<qresource prefix="/"> <file alias="SennLogo.ico">../ServiceTools_Shared_QT/Standard/SennLogo.ico</file> </qresource>
Then you can access it by
":/SennLogo.ico". Alias can be anything. Contain a path, no extension etc. Sorta an id.
The other thing you can do is place the .qrc file along with the resources to avoid the ".." altogether. Since it's a shared resource the .qrc can be shared as well. You can have a separate, local .qrc file for resources specific to that single project.
Hey, great, thanks for the quick answer! This works, for everyone else who will have the same issue. I didn't find it before, but after your hints I figured that one can go to the .qrc file, perform a right click on it, open in editor and assign the alias directly to the ressource.