简体   繁体   中英

How to open a .pdf file from QML?

Is there any way to open a .pdf file from QML or I have to do it in C++ via QDesktopServices , and if I used QDesktopServices would it work without any problem in Android .

Thanks.

Is there any way to open a .pdf file from QML or I have to do it in C++ via QDesktopServices

The only thing I am aware of is the following:

Qt.openUrlExternally("http://stackoverflow.com/questions/23001582/how-to-open-a-pdf-file-from-qml/23002658");

Based on the comments, it seems to work on Android

In your particular case, it would become:

Qt.openUrlExternally("path/to/my/foo.pdf");

and if I used QDesktopServices would it work without any problem in Android

The question lacks a question mark, but nitpicking aside, this oughta work. This bug was also fixed in Qt 5.2.0. That is why I asked about the version, but other than this, I am not aware of any other critical issues:

QDesktopServices::openUrl crashes Application

You can do this from QML using the V-Play FileUtils: https://v-play.net/doc/fileutils/

fileUtils.openFile("<path to pdf file>")

Here is an example code that downloads a PDF from the web and opens it using the default application on Android and iOS: https://v-play.net/web-editor/?snippet=ce64a995

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM