Capton
Capton

Reputation: 67

Closing an external application with qt

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.

Upvotes: 1

Views: 890

Answers (1)

Pavel Strakhov
Pavel Strakhov

Reputation: 40512

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.

Upvotes: 6

Related Questions