Reputation: 1117
I need to add a pdf file to my resource folder, which I can open from the application with the click of a button (kind of like a Help file).
So my confusions are:
QDesktopServices::openUrl(QUrl("/Resource Files/Help.pdf"));
Upvotes: 1
Views: 1588
Reputation: 32685
To add the resource file into your project, right click on the project in the Projects pane and click Add New...
and then Qt>Qt Resource file
, enter a name for it and after finishing something is added to your .pro file like :
RESOURCES = myResource.qrc
Once added into the pro file, a separate .qrc file will be added into your Qt project with which you can double click and add your desired resources like icons, translation files etc. Open the resource file and add your pdf file there.
To open the pdf file from resources, you should first copy it to some location for example in the application directory path :
QFile HelpFile("qrc:/myFile.pdf");;
HelpFile.copy(qApp->applicationDirPath().append("/myFile.pdf"));
Next you can open the pdf file by :
QDesktopServices::openUrl(QUrl::fromLocalFile(qApp->applicationDirPath().append("/myFile.pdf")));
Upvotes: 3