How to add PDF files in QT application.
-
How to add PDF files in QT application.
I am developing the Qt application. I want to add some PDF files related to application manual into Help section. how can add this PDF files in Qt application.
ex. in Qt creator only have Help section there we get some pdf files related to qt api.
Thank You.
-
Please help me here.
any hint ? -
@Pranit-Patil
patience.... no need to bump the thread after 1hTake a look at the QtHelp module for example.
-
Save the pdf file inside your resources (.qrc files) then you can open them via:
QString destinationTemp = QDir::fromNativeSeparators(QDir::tempPath()); if(!destinationTemp.endsWith('/')) destinationTemp.append('/'); QString fileName = "manual"; if(QFile::exists(destinationTemp + fileName + ".pdf"){ fileName = "manual %1"; unsigned int i=0 for(;QFile::exists(destinationTemp + fileName.arg(i) + ".pdf");++i){} fileName = fileName.arg(i); } QFile::copy(":/docs/manual.pdf",destinationTemp + fileName + ".pdf"); QDesktopServices::openUrl(QUrl::fromLocalFile(destinationTemp + fileName + ".pdf"));
P.S.
this is not the first time you are warned not to bump the topic too fast, let's make it the last, shall we?! -
Thanks to all.
I got simple solution to open PDF file on Windows System through QT.
Save your pdf file in Build directory then you can open them via:QDir dir;
QString path = dir.absolutePath();
path.append("/Manual.pdf");
QDesktopServices::openUrl(QUrl::fromLocalFile(path));its work fine for me.
-
@Pranit-Patil You don't specify explicitly where to store the file. I guess it will be current working directory. If this directory is not writeable by the user it will not work. You should use http://doc.qt.io/qt-5/qtemporaryfile.html
-
@Pranit-Patil Sure, but what will happen when you deploy/install your app?