Question

I have a file in /home/me/xmls/foo/bar.xml and a correct qrc file containing this path

The folowing code :

QFileInfo f (":/foo/bar.xml");
cout<<f.absoluteFilePath().toAscii().data()<<endl;

outputs:

:/foo/bar.xml

when i was expecting:

/home/me/xmls/foo/bar.xml

Is there any way to recover the absolute path in the system of a QRessource loaded file ?

Was it helpful?

Solution

QResource encodes its contents into a file that gets compiled into the final binary. So, no I would expect it is not possible to get the original path at run time. As the Qt docs state: -

The Qt resource system is a platform-independent mechanism for storing binary files in the application's executable

Also, it doesn't make sense to want the original path, as other users are unlikely to have the file at that location.

OTHER TIPS

This :

QFileInfo f (":/foo/bar.xml");

means that you are going to load a file from the resource file. Basically, this is a library (static or shared), which contains resources (images, translations, etc).

That is a standard syntax to access a file in the resources, as explained in their documentation for the resources.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top