【问题标题】:qt QUrl Opening a pdfqt QUrl 打开一个 pdf
【发布时间】:2017-11-02 12:37:00
【问题描述】:

我正在尝试通过 Qt 的“DesktopServices”类使用默认应用程序打开一个 pdf 文件。

但我想出了一个 ShellExecute

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

这是我的代码:

#include <QDesktopServices>
#include <QUrl>

}

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

【问题讨论】:

  • 试试:QDesktopServices::openUrl(QUrl:::fromLocalFile("C:/PMPS/PMPSv1/Instuctionsforuse.pdf"));
  • 仍然出现同样的错误:ShellExecute 'file:///C:/PMPS/PMPS??v1/Instuctionsforuse??.pdf' failed (error 2)。
  • 试试QDesktopServices::openUrl(QUrl:::fromLocalFile("C://PMPS//PMPS‌v1//Instuctionsforuse‌​.pdf"));
  • QDesktopServices::openUrl(QUrl:::fromLocalFile("C:\\PMPS\\PM‌​PS‌v1\\Instuctionsfo‌​ruse‌​.pdf"));
  • 还是一样的错误...

标签: qt pdf qurl


【解决方案1】:

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

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

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

 qDebug() << localfile.toLocalFile();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    • 1970-01-01
    • 2021-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多