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

Sergio Jovani lesergi at gmail.com
Mon Jan 26 08:55:00 GMT 2009


Hi,

You have to specify fromLocalFile() in QUrl():

DesktopServices().openUrl(QUrl.fromLocalFile("/home/piotr/test2/lol
bar/photo_4900_8ea80c_huge.jpg"))

Bye!

2009/1/26 piotr maliński <riklaunim at gmail.com>:
>
>
> 2009/1/26 David Boddie <david at boddie.org.uk>
>>
>> On Sun Jan 25 22:17:46 GMT 2009, piotr malinski wrote:
>>
>> > 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)
>>
>> Perhaps try encoding the URL first:
>>
>>
>> http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qurl.html#toEncoded
>>
>> This may be related to a bug that was apparently fixed in Qt 4.4.0:
>>
>>
>> http://www.qtsoftware.com/developer/task-tracker/index_html?method=entry&id=194046
>>
>> You don't say which version of Qt you are using. If it's later than Qt
>> 4.4.0,
>> it would be good if you could report this as a bug using the Task Tracker.
>>
>> David
>> _______________________________________________
>> PyQt mailing list    PyQt at riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
>
> PyQt 4.4.4-r1, Qt 4.4.2, and using:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
>
> d = QDesktopServices()
>
> x = '/home/piotr/test2/lol bar/photo_4900_8ea80c_huge.jpg'
> x = unicode(QUrl(x).toEncoded()
> print x
> print QUrl(x).isValid()
> d.openUrl(QUrl(x))
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Doesn't help. So is it a Qt bug?
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>



More information about the PyQt mailing list