[PyQt] Object lifetime issues with QWebEngineUrlSchemeHandler and QBuffer
Detlev Offenbach
detlev at die-offenbachs.de
Wed Sep 14 17:12:56 BST 2016
Hi Florian,
you could inspect the new web browser of my eric IDE (deafult branch). It has already
been ported to QtWebEngineWidgets and is using custom scheme handlers as well.
Detlev
On Wednesday 14 September 2016, 09:49:25 Florian Bruhin wrote:
> Hey,
>
> I tried implementing a custom QWebEngineUrlSchemeHandler yesterday,
> and ran into some weird object lifetime issues I can't quite explain.
>
> The attached request1.py is the one which works fine, and displays
> "Hello World" with a custom test:foo URL.
>
>
> In request2.py, I removed a global reference to SchemeHandler, so
> "handler" is local in install_scheme_handler().
>
> Now, despite setting the parent of SchemeHandler to the QApplication
> instance, it seems to go away somehow and I get an
> "ERR_UNKNOWN_URL_SCHEME" error page.
>
> Why?
>
>
> In request3.py, the global reference is back, but I use a QBuffer to
> which I pass a byte string instead of writing to it in requestStarted.
> Here, I get a segfault:
>
> #0 QBuffer::readData (this=0xe06740, data=0x7fffd4013000 "", len=32768)
> at io/qbuffer.cpp:412 #1 0x00007fffecd579ae in ?? () from
> /usr/lib/python3.5/site-packages/PyQt5/QtCore.so #2 0x00007ffff4ae3e0a in
> QIODevice::read (this=0xe06740, data=0x7fffd4013000 "", maxSize=32768) at
> io/qiodevice.cpp:1047 #3 0x00007fffe734232a in
> QtWebEngineCore::URLRequestCustomJob::ReadRawData (this=<optimized out>,
> buf=0x7fff9c1692c0, bufSize=32768) [...]
>
> I explicitly keep a reference to both the QBuffer and to the
> underlying byte string, to make sure they never get collected, so why
> is this happening?
>
>
> Also, with request1.py, I never delete the QBuffer - when can I do so?
> Should I do job.destroyed.connect(buf.deleteLater)?
>
>
> Thanks,
>
> Florian--
*Detlev Offenbach*
detlev at die-offenbachs.de
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160914/5cad5b26/attachment-0001.html>
More information about the PyQt
mailing list