[PyQt] Synchronous WebView.load()

Phil Thompson phil at riverbankcomputing.com
Fri Jul 2 09:04:40 BST 2010


On Fri, 02 Jul 2010 00:31:40 -0500, alan moore <me at alandmoore.com> wrote:
>> As I understand it, the webview doesn't actually load the page and
update
>> itself until the method call returns; at which point it loads the new
>> page and
>> updates the history.

No, the load starts straight away but may not finish until some time later
(probably after the method returns).

The view will update itself when it has enough of the page loaded to be
usefully displayed.

The display won't actually change until the even loop runs.

> To illustrate the problem I'm having a little more clearly, I've 
> attached a sample script.  The script is supposed to conduct a brief 
> tour of a list of websites when you hit the "go" button on the browser 
> toolbar.  Each site shows for five seconds, then the next on loads.
> 
> Only that's not what happens.  If you run it, you'll see that hitting 
> "go" causes the browser to hang for about 20 seconds, then the final 
> comment is all that shows.  In other words, for the whole duration of 
> the method call, the main window is asleep.
> 
> I guess this is just another instance of the trouble I was running into 
> on my other program, which I posted a demonstration script for earlier 
> today.  I would really appreciate any help on this matter.

You need to get rid of your loop and sleep() and connect to the
QWebView.loadFinished() signal. In the connected slot start a timer for 5
seconds. When that timer times out you can then set the next URL.

Phil


More information about the PyQt mailing list