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 ?

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top