[webkit-qt] Add a function to the 'window' DOM/Javascript object

Guillaume BIENKOWSKI guitreize at gmail.com
Tue Aug 16 08:15:57 PDT 2011

Hey guys,

I'm trying to add a _function_ to the window Javascript object exposed
by QtWebkit in all its pages.

I know how to add an _object_ to this window object, proceeding like
this in my QWebView:

> QWebFrame *frame = page()->mainFrame();
> MyObject *object = new MyObject();
> frame.addToJavascriptWindowObject( "myObject", object );

And then, thanks to the magics of Qt (here:
), any slot on my object will be callable from the Javascript like

> window.myObject.mySlot( argument );

Now, what I want to do is to have this in Javascript:

> window.myFunction( argument );

How can I add the "myFunction" _function_ to the window object?
I suppose that the addToJavascriptWindowObject() won't do, since an
object is not "executable" in Javascript.
I looked into the QWebFrame object to see what this function does, but
it seems that the window object is not easily reachable from the Qt

Any idea?


More information about the webkit-qt mailing list