[PyQt] QWebEnginePage.print() raises SIGSEGV

Florian Bruhin me at the-compiler.org
Mon Apr 8 18:04:15 BST 2019


On Mon, Apr 08, 2019 at 01:31:45PM -0300, Julio César Gázquez wrote:
> It results in the following, both in PyQt 5.12.1 from wheel and 5.10.1
> from Ubuntu repos: [...]

The Qt docs for QWebEnginePage::print say:

    It is the users responsibility to ensure the printer remains valid until
    resultCallback has been called.

So you'll need to make sure to keep a reference to the dialog (or the printer)
until the callback is called - for example, by using a nested function:

    def print_page():
    
        def cleanup(_success):
            dialog.deleteLater()
    
        dialog = QtPrintSupport.QPrintDialog(w)
        if dialog.exec_() == QtPrintSupport.QPrintDialog.Accepted:
            page.print(dialog.printer(), cleanup)

Florian

-- 
https://www.qutebrowser.org | me at the-compiler.org (Mail/XMPP)
   GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
         I love long mails! | https://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190408/c0557f96/attachment.sig>


More information about the PyQt mailing list