【问题标题】:PyQT | QDesktopServices.openUrl Doesn't work if path has spacesPyQT | QDesktopServices.openUrl 如果路径有空格则不起作用
【发布时间】:2017-03-12 13:12:10
【问题描述】:

我正在尝试使用 QDesktopServices 让系统打开指定的文件或文件夹。

下面的代码非常适用于其中没有空格但如果没有空格则无法执行的路径

def openFile(self):

    print self.oVidPath
    print "\n"
    url = QUrl(self.oVidPath)
    QDesktopServices.openUrl(url)
    self.Dialog.close()

带有空格的路径的输出是

/home/kerneldev/Documents/Why alcohol doesn't come with nutrition facts.mp4


gvfs-open: /home/kerneldev/Documents/Why%20alcohol%20doesn't%20come%20with%20nutrition%20facts.mp4: error opening location: Error when getting information for file '/home/kerneldev/Documents/Why%20alcohol%20doesn't%20come%20with%20nutrition%20facts.mp4': No such file or directory

我已验证指定的路径存在。

请帮忙

【问题讨论】:

    标签: python pyqt pyqt5 qurl qdesktopservices


    【解决方案1】:

    您需要使用file:// url,否则QUrl 会将路径视为网络url,并将对其进行编码以供在该上下文中使用。所以试试这个:

    url = QUrl.fromLocalFile(self.oVidPath)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-28
      • 1970-01-01
      • 2013-05-04
      • 2019-01-31
      • 1970-01-01
      • 2012-10-05
      • 1970-01-01
      相关资源
      最近更新 更多