[PyQt] Object lifetime issues with QWebEngineUrlSchemeHandler and QBuffer
Florian Bruhin
me at the-compiler.org
Wed Sep 14 08:49:25 BST 2016
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
--
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
GPG: 916E B0C8 FD55 A072 | http://the-compiler.org/pubkey.asc
I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: request1.py
Type: text/x-python
Size: 823 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160914/b75bc856/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: request2.py
Type: text/x-python
Size: 787 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160914/b75bc856/attachment-0001.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: request3.py
Type: text/x-python
Size: 905 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160914/b75bc856/attachment-0002.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160914/b75bc856/attachment.sig>
More information about the PyQt
mailing list