[PyQt] Link between a QWebViev and a JavaScript program

David Boddie david at boddie.org.uk
Sun Apr 19 23:28:57 BST 2009


On Sun Apr 19 20:51:49 BST 2009, projetmbc wrote:
> Simon Edwards a écrit :
> > projetmbc wrote:
> >> I'm seeking for information about how to comunicate from PyQt with a
> >> JavaScript program.
> >
> > QWebFrame's evaluateJavaScript() might be a start.
>
> Indeed I'm looking for a simple example rather than an abstract one.

The porting of the C++ Qt examples to Python has fallen behind since Qt 4.3
so there aren't any simple WebKit examples included with PyQt. Still, the
recent Monster Evolution experiments on Qt Labs include a Python version
of a program that integrates with WebKit's JavaScript engine:

http://labs.trolltech.com/blogs/2009/04/07/monster-evolution-in-qt-episode-2-attack-of-the-squirrelfish/

QWebFrame's addToJavaScriptWindowObject() method lets you insert an instance
of a QObject subclass into the page. You can expose methods to JavaScript,
but you have to declare them as slots with the @pyqtSignature() decorator.
The example code can be found here:

http://labs.trolltech.com/gitweb?p=GraphicsDojo;a=blob;f=webmonster/webmonster.py

David



More information about the PyQt mailing list