PDA

View Full Version : QWebEnginePage::printToPdf() - how to tell when finished?



ce_nort
18th February 2017, 20:23
I'm using the QWebEnginePage function printToPdf() to save a pdf file. I then want to open it in the appropriate application using QDesktopServices. When I try to do this, I am getting a ShellExecute failed error 2 (file not found). My problem seems to be that QDesktopServices tries to open the pdf before it is finished being created, because if I try to open that same exact same PDF using QDesktopServices the next time the program is run (by hardcoding the path in so it grabs the previously generated pdf as opposed to the one being created concurrently) it works fine. It there a way to determine when printToPdf has completed so I can trigger QDesktopServices after that? I can't seem to find any information on the topic other than this (https://forum.qt.io/topic/68294/qwebenginepage-and-printtopdf-qt-5-7-issue) question from 8 months ago that remains unanswered.

anda_skoa
19th February 2017, 13:24
Sadly that overload doesn't seem to have a result/status callback to allow the application to know when the operation ended.

You could either use one of the other two print functions or monitor the target directory with a QFileSystemWatcher for the PDF to appear.

Cheers,
_

ce_nort
21st February 2017, 18:50
QFileSystemWatcher did the trick, thank you!