Python PyQT | QDesktopServices.openUrl不';如果路径有空格,则不工作

Python PyQT | QDesktopServices.openUrl不';如果路径有空格,则不工作,python,pyqt,pyqt5,qurl,qdesktopservices,Python,Pyqt,Pyqt5,Qurl,Qdesktopservices,我正在尝试使用QDesktopServices让系统打开指定的文件或文件夹 下面的代码适用于没有空格但无法执行的路径 def openFile(self): print self.oVidPath print "\n" url = QUrl(self.oVidPath) QDesktopServices.openUrl(url) self.Dialog.close() 带空格的路径的输出是 /home/kerneldev/Documents/Why a

我正在尝试使用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
我已验证指定的路径是否存在


请帮助您需要使用
文件://
url,否则
QUrl
会将路径视为网络url,并对其进行编码以供在该上下文中使用。因此,请尝试以下方法:

url = QUrl.fromLocalFile(self.oVidPath)

您需要使用
文件://
url,否则
QUrl
会将路径视为网络url,并对其进行编码以供在该上下文中使用。因此,请尝试以下方法:

url = QUrl.fromLocalFile(self.oVidPath)