[Qt-interest] returning a QObject to javascript in WebKit
David Boddie
david.boddie at nokia.com
Thu Jun 4 14:59:43 CEST 2009
Paul Dixon wrote:
> One rather ugly hack I'm now considering is to use
> addToJavaScriptWindowObject to drop the object I want to return into
> the window object with a random name, then have my slot return the
> name of the object instance instead:
[...]
> The JS can be written to check if the return value is a string, and if
> it is, grab the object from the window.:
>
> var foo=myapp.helloWorld();
> if (typeof foo == "string")
> {
> foo=window[foo];
> }
Or you could use a helper function in JavaScript for each type that you
want to create that uses a predetermined name for the object created
from C++:
MyObject = function(argument)
{
_MyObject_factory.createMyObject(argument);
return _wrapper;
}
where _MyObject_factory is an object added to the script environment and
_wrapper is a new object introduced by the createMyObject() slot.
This makes it possible to create new instances like this:
var myobject = MyObject(argument);
David
--
David Boddie
Senior Technical Writer
Nokia, Qt Software
More information about the Qt-interest-old
mailing list