PDA

View Full Version : get the real path of a resource file



szisziszilvi
8th June 2011, 14:46
Hi,

is it possible to get the real path of a file that is added to the project with Qt's resource system?

Namely I have "test.qrc" added to the project and a file in that that can be referred with ":/res/file.txt" but this is of course not the real path in the file system. Now the class QFile can handle with the problem (would be dissapointing otherwise... :) ) but I can't give this string for example to an std::ifstream or it is not enough information for otput logs etc.

mvuori
8th June 2011, 17:20
I don't know whether this works, but it just might:
QDir::absoluteFilePath ( const QString & fileName )

Lesiok
8th June 2011, 18:03
Resources are compiled in the executable (or exits as external binary file containing ALL files specified in QRC). So I don't think that You can use this with standard file system mechanism.

szisziszilvi
9th June 2011, 08:46
I tried QFileINfo's absoluteFilePath, but it returns also :/res/file.txt
I have the bad feeling that unfortunatelly Lesiok is right.

ChrisW67
9th June 2011, 08:58
Lesiok is absolutely right. There is no file on the (deployed) file system corresponding to ":/res/file.txt". If you need that the be the case then don't use the resources system, or copy the data from the resource system to a dynamically allocated temporary file for external consumption.

Lesiok
9th June 2011, 11:46
All is described here (http://doc.qt.nokia.com/latest/resources.html)