[PyQt] Subclassing a Qt non-QObject class
Phil Thompson
phil at riverbankcomputing.com
Fri May 10 09:14:18 BST 2019
On 10/05/2019 02:50, Wallboy wrote:
> Hello,
>
> I'm working with QNetworkCookieJar and QNetworkCookie in PyQt5. I would
> like
> a custom QNetworkCookie class to add some additional attributes and
> methods
> of my own.
>
> I would like it so that when I insert cookie/s into the
> QNetworkCookieJar
> and retrieve them later from the cookie jar, they would return my
> custom
> subclass instance. However it seems when I insert a cookie instance of
> my
> subclass into the jar, the subclass information is lost later on when I
> retrieve the cookies from the jar.
>
> Is this because QNetworkCookie is not a QObject? I don't know the inner
> details of how the PyQt bindings work when converting classes from
> PyQt->Qt
> and vice versa.
>
> Is there a way I could achieve what I want in PyQt?
The issue isn't whether the class is a QObject or not, it is how the
instance is passed - a pointer or a const reference. In this case it is
a const reference so the jar takes a copy of the cookie and it can only
copy what it knows about, ie. the base QNetworkCookie. It wouldn't work
in C++ either.
Phil
More information about the PyQt
mailing list