0

I am trying to open a pdf file with the default application through Qt's "DesktopServices" class.

But I am coming up with a ShellExecute

'file:///C:/PMPS/PMPSv1/Instuctionsforuse.pdf' failed (error 2). problem.

Here is my code:

#include <QDesktopServices>
#include <QUrl>

}

void Dialog::guideButtonClicked()
{
QDesktopServices::openUrl(QUrl("file:///C:/PMPS/PMPSv1/Instuctionsforuse.pdf"));
}
4

1 回答 1

0

如果您的 Url 中已经有处理程序(例如file://等),或者您的 Url 已经编码并且应该在没有任何转换和更改的情况下使用,请使用QUrl::fromUserInput函数。当字符串还不是有效的 URL 时,将执行最佳猜测,做出各种与 Web 相关的假设。

QUrl localfile = QUrl::fromUserInput("file:///C:/PMPS/PMPSv1/Instuctionsforus‌​e.pdf"); 

您可以通过以下方式检查它是否正确:

 qDebug() << localfile.toLocalFile();
于 2017-11-02T12:57:24.170 回答