[PyQt] QDesktopServices openUrl doesn't work if URL-Path has spaces etc.

piotr maliński riklaunim at gmail.com
Sun Jan 25 22:17:46 GMT 2009


Here is an example script:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
from PyQt4.QtCore import *
from PyQt4.QtGui import *

d = QDesktopServices()

x = '/home/piotr/test2/lol bar/photo_4900_8ea80c_huge.jpg'
print QUrl(x).isValid()
d.openUrl(QUrl(x))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The problem is it won't work if there is a space in the path - "lol
bar", for spaceless paths it works (also for example on windows it
needs paths with slashes not backslashes...). How can I make the path
valid for QDesktopServices? (the QUrl itself is valid)

Running the script will result in error:
file:///home/piotr/test2/lol%2520bar/photo_4900_8ea80c_huge.jpg does
not exist.


More information about the PyQt mailing list