[webkit-qt] Can I return MyQObject from a slot.

Luciano Montanaro mikelima at cirulla.net
Sun Nov 29 02:57:50 PST 2009


On sabato 28 novembre 2009, Mital Vora wrote:
> hey guys,
> 
> I am a newbie to Qt. I am trying to Inject my custom Object in JavaScript
> space using QWebFrame::addToJavaScriptWindowObject( ) method. I have few
> doubts related to this.

I'm relatively a newbie too, but I've done some experiment.

> 
> 1) can I return custom datatype (a class derived from QObject) MyQObject
> from a slot.
> 

You can do this. I think it has to be a QObject, though.
And you should return it as QObject or QWidget, not as a subclass.

> 2) can I set MyQObject2 as property of MyQObject1 such that In javascript I
> am able to access various properties of MyQObject2 using
> myQObject1.myQObject2.prop1.
> 

I've not tried this, but it should be basically the same as the case above.
Since properties are visible from JavaScript and QObjects slots can be invoked 
from JavaScript, a QObject property should work.


> 3) can I do things like "var obj = new MyQObject(["abc", 1]);" using the
>  new operator to create a new object of a particular type.
> 

I've never done this; the closer thing I tried was a MyObjectFactory returning 
a MyObject instance.

Since a QObject constructor is not a slot, I don't think this works.
But you can try declaring the constructor Q_INVOKABLE and see if it works.
Be sure to tell me if it does... :)

> I am able to do all these using JavaScriptCore in windows. Please help me
> figure out how should I do it using Qt.
> 

What I'm still trying to find out is how to obtain a pointer to the currently 
used engine (to return an array of values, for example).

Luciano


-- 
Luciano Montanaro //
                \X/ mikelima at cirulla.net


More information about the webkit-qt mailing list