Qt6: QUrl and UrlFormattingOption vs. ComponentFormattingOption

Phil Thompson phil at riverbankcomputing.com
Mon Nov 29 12:37:59 GMT 2021


On 28/11/2021 16:21, Florian Bruhin wrote:
> Hi again,
> 
> On Thu, Aug 26, 2021 at 05:19:57PM +0100, Phil Thompson wrote:
>> 
>> On 26/08/2021 16:34, Florian Bruhin wrote:
>> > Hi,
>> >
>> > Qt's QUrl.toString() (and other methods taking QUrl.UrlFormattingOption)
>> > are a bit weird, because they *also* can take
>> > QUrl.ComponentFormattingOption:
>> > https://doc.qt.io/qt-6/qurl.html#UrlFormattingOption-enum
>> >
>> > However, combining the two doesn't seem to be possible anymore with
>> > PyQt6:
>> >
>> >     >>> from PyQt6.QtCore import QUrl
>> >     >>> > > QUrl("https://example.org").toString(QUrl.UrlFormattingOption.RemovePassword > > | QUrl.ComponentFormattingOption.FullyEncoded)
>> >     Traceback (most recent call last):
>> >       File "<stdin>", line 1, in <module>
>> >     TypeError: unsupported operand type(s) for |:
>> > 'UrlFormattingOption' and 'ComponentFormattingOption'
>> >
>> > and converting won't work either:
>> >
>> >     >>> > > QUrl("https://example.org").toString(QUrl.UrlFormattingOption.RemovePassword
>> > |
>> > QUrl.UrlFormattingOption(QUrl.ComponentFormattingOption.FullyEncoded))
>> >     ValueError: <ComponentFormattingOption.FullyEncoded: 32505856> is
>> > not a valid QUrl.UrlFormattingOption
>> >
>> > Florian
>> 
>> Fixed in the next PyQt6 snapshot.
> 
> After looking at this again I found another related issue: While
> combining the two now works as expected, only passing a
> ComponentFormattingOption fails, while working as expected with PyQt5:
> 
> $ python3 -c "from PyQt5.QtCore import QUrl; u =
> QUrl('https://example.org/');
> print(u.toString(QUrl.ComponentFormattingOption.PrettyDecoded))"
> 
> $ python3 -c "from PyQt6.QtCore import QUrl; u =
> QUrl('https://example.org/');
> print(u.toString(QUrl.ComponentFormattingOption.PrettyDecoded))"
> Traceback (most recent call last):
>   File "<string>", line 1, in <module>
> TypeError: toString(self, options: QUrl.UrlFormattingOption =
> QUrl.FormattingOptions(QUrl.PrettyDecoded)): argument 1 has unexpected
> type 'ComponentFormattingOption'
> 
> Florian

Hopefully fixed in the next snapshot.

Thanks,
Phil


More information about the PyQt mailing list