How to add PDF files in QT application.
-
wrote on 6 Sept 2018, 04:48 last edited by
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.
-
wrote on 6 Sept 2018, 06:01 last edited by
Please help me here.
any hint ? -
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.
-
wrote on 6 Sept 2018, 07:54 last edited by VRonin 9 Jun 2018, 10:26
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?! -
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?!wrote on 6 Sept 2018, 08:11 last edited by JonB 9 Jun 2018, 08:12This post is deleted! -
wrote on 16 Oct 2018, 13:39 last edited by
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.
-
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 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
wrote on 17 Oct 2018, 05:30 last edited by@jsulm i mention Save pdf file in Build Directory.
-
@jsulm i mention Save pdf file in Build Directory.
@Pranit-Patil Sure, but what will happen when you deploy/install your app?