[PyQt] segmentation faults common when using QWebView

Hans-Peter Jansen hpj at urpla.net
Mon Nov 29 17:26:27 GMT 2010

On Monday 29 November 2010, 16:54:42 Brandon Craig Rhodes wrote:
> I think that there is a bright future in using PyQt4 with a QWebView
> object for writing basic web tests, and for web automation.  My early
> experiments suggest that it is a much simpler and faster solution,
> when one needs web page browsing with JavaScript enabled, than a
> heavyweight technique like running and remotely controlling a
> separate browser process.
> But though my first few page loads and clicks went well, I quickly
> found that sites of any complexity would cause my Python script to
> crash with a segmentation fault.  Many of my early examples were
> non-deterministic - the script would sometimes crash, but sometimes
> succeed - but I have now found a test script which always crashes,
> and that therefore might serve as a good example of this bug here on
> the mailing list.
> The script is attached to this email.  Its output when I run it
> against the PyQt4 shipped with Ubuntu Maverick is this:
> $ python2.6 qtcrash.py
> 4.7.0
> 4.7.4
> zsh: segmentation fault  python2.6 qtcrash.py
> When I download and install the current PyQt4 snapshot instead, this
> is the output:
> $ ./v/bin/python2.6 qtcrash.py
> 4.7.0
> snapshot-4.8.2-f509333f6b01
> zsh: segmentation fault  ./v/bin/python2.6 qtcrash.py
> Is anyone else able to reproduce this?  Where would I get started in
> tracking down why this code causes PyQt4 to produce a segmentation
> fault?  Thanks for any guidance!

From what I can see, you're missing fundamental concepts of the 
asynchronous nature of QtWebView. You should control your test flow 
with signals, instead of a timer, e.g.:

    def callback1(self):
        self.webview = QtWebKit.QWebView()
	# you need to wait for finishing the load

    def callback1done(self):
        self.current_callback = self.callback2

This moves the issue into the next step of course, but I'm sure, you get 
the idea.


More information about the PyQt mailing list