ce_nort
17th April 2017, 18:05
I am using QDesktopServices to open pdfs generated by QWebEnginePage and saved to the local filesystem with printToPdf(). I use a QFileSystemWatcher to watch the directory the pdf is being saved in, otherwise QDesktopServices will try to open the pdf before it exists. The code for opening the pdf is as follows:
QUrl url_of_file = QUrl::fromLocalFile("path/to/file.pdf");
QDesktopServices::openUrl(url_of_file);
The above works totally fine for the first pdf that is generated. It opens the correct pdf in the most appropriate program (e.g., Adobe Acrobat). The problem that I am encountering is that the second time this is used (i.e., a second pdf has been generated and attempted to open without closing the program in between) the first pdf that was generated gets re-opened instead of the correct, second pdf that was just generated. The problem seems to be specifically with the QDesktopServices class, since if I output url_of_file it does have the path to the correct pdf, but for some reason it is opening the wrong one. The same problem occurs both in a Mac environment using Preview to view pdfs, and a Windows environment using Adobe Acrobat. Any idea why this might be? I have confirmed that the second/correct pdf does exist at the time of attempted opening. Is there some sort of caching that occurs with QDesktopServices? The file paths are 90% the same until the end, since the difference in file names is mainly based on the date and time they were generated, but I can't imagine that there's some sort of character limit. I'm stumped!
QUrl url_of_file = QUrl::fromLocalFile("path/to/file.pdf");
QDesktopServices::openUrl(url_of_file);
The above works totally fine for the first pdf that is generated. It opens the correct pdf in the most appropriate program (e.g., Adobe Acrobat). The problem that I am encountering is that the second time this is used (i.e., a second pdf has been generated and attempted to open without closing the program in between) the first pdf that was generated gets re-opened instead of the correct, second pdf that was just generated. The problem seems to be specifically with the QDesktopServices class, since if I output url_of_file it does have the path to the correct pdf, but for some reason it is opening the wrong one. The same problem occurs both in a Mac environment using Preview to view pdfs, and a Windows environment using Adobe Acrobat. Any idea why this might be? I have confirmed that the second/correct pdf does exist at the time of attempted opening. Is there some sort of caching that occurs with QDesktopServices? The file paths are 90% the same until the end, since the difference in file names is mainly based on the date and time they were generated, but I can't imagine that there's some sort of character limit. I'm stumped!