[Qt-interest] Calling QT objects from script embedded in html pages.

David Boddie david.boddie at nokia.com
Wed May 20 18:27:02 CEST 2009


jeanmichel.123 at free.fr wrote:

> Using debug mode, this lead me one step forward, with the error
> description:
> 
> message: "Can't find variable: QString"
> name: "ReferenceError"
> 
> This occured in the exact following line:
> var qs = new QString ( 'C:/a.obj'  );

This won't work because QString is not exposed to the JavaScript engine in
the browser. Generally speaking, Qt classes are not accessible from scripts
running in the browser.

> What is the issue?
> Did I miss some documentation?

It sounds like you need to expose a C++ API to your scripts using the
QWebFrame::addToJavaScriptWindowObject() function:

  http://doc.qtsoftware.com/4.5/qwebframe.html#addToJavaScriptWindowObject

This is how the Form Extractor example works:

  http://doc.qtsoftware.com/4.5/webkit-formextractor.html

Take a look at the FormExtractor class to see how it adds itself to the
script environment:

  http://doc.qtsoftware.com/4.5/webkit-formextractor-formextractor-cpp.html

The script itself is in the form.html file included with that example, which
is unfortunately not online.

David
-- 
David Boddie
Senior Technical Writer
Nokia, Qt Software



More information about the Qt-interest-old mailing list