PDA

View Full Version : file opening from Resorce



anh5kor
13th October 2014, 07:41
Hello,

I have added Pdf file to my Resource folder.And trying to open a file


QDesktopServices::openUrl(QUrl(":/logo/CA185_EMU_v120.pdf", QUrl::TolerantMode));


Where logo is a Resource folder in my project folder directory.But still I am not able to open the pdf.

if I give the full path


QDesktopServices::openUrl(QUrl("file:///D:/EMU6Config/logo/CA185_EMU_v120.pdf", QUrl::TolerantMode));


I am able to open the file.But I want it should open from my resource file.
Please let know some solution.

Cyrano
13th October 2014, 08:55
In the past I had a similar problem (retrieving url using a resource file) and i found that the solution was to use this kind of syntax:



QString urlstring = "qrc:/PathToResource";
QUrl url = QUrl(urlstring);


In my problem I was using url with "QXmlQuery.setQuery" function... so I don't know if this solution works fine with "QDesktopServices::openUrl" function too.

In your case it should be:

QDesktopServices::openUrl(QUrl("qrc:/logo/CA185_EMU_v120.pdf", QUrl::TolerantMode));

wysota
13th October 2014, 08:56
Store contents of the file in QTemporaryFile (e.g. via QTemporaryFile::createNativeFile()) and then open it with openUrl(). Obviously your system url handler does not know how to look into a Qt-based binary to access a file stored within.