Please how do i close an application i previously opened with QDesktopServices::OpenURL
in qt c++. Because i need to update text in a PDF i already opened outside my application at a point in time.
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFormat(QPrinter::pdfFormat);
printer.setOutputFileName("file.pdf");
doc.print(&printer); // doc is QTextDocument
QDesktopServices::openUrl(QUrl("file.pdf"));
And also i would like to know the difference between QDesktopServices::OpenURL
and Qt::openUrlExternally
and basically when to use them.
You can't close an external application opened by QDesktopServices::OpenURL
. There is no such option, and this method provides no information about started process that could be used to close it.
You can use native C++ platform-dependent functions to determine the path of PDF viewer executable. Then you can use QProcess
to launch it. So kill()
and terminate()
can be used to close the application.
Qt::openUrlExternally
can be used in QML code, and QDesktopServices::OpenURL
can be used in C++ code. That's the only difference. I've read Qt::openUrlExternally
sources, it calls QDesktopServices::OpenURL
internally.
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.