views:

234

answers:

1

I need to get access to the javascript QScriptEngine in a QWebFrame. Is that possible?

Well, at least I think I need access to it. In response to a javascript call I need to allocate a new object, return it to javascript and hand ownership of the object to javascript so that it can be garbage collected. It looks like QScriptEngine::newQObject would allow me to transfer ownership. Maybe this isn't the right approach.

Thanks! Alex

A: 

Have you noticed void QWebFrame::addToJavaScriptWindowObject ( const QString & name, QObject * object ) method?

From the help:

Make object available under name from within the frame's JavaScript context. The object will be inserted as a child of the frame's window object.

Qt properties will be exposed as JavaScript properties and slots as JavaScript methods.

Maybe that will help you.

Piotr Dobrogost
Yes, I was hoping for another way to do it since the object won't necessarily have a name. I just tried addToJavaScriptWindowObject (using a random name) but haven't been able to confirm that the object actually gets garbage collected, ie. my destructor never gets hit. Does the javascript function collectgarbage() actually exist? I can't tell. Thanks.
Alex Brown