[Interest] Using Non-QObject-derived types in Javascript
Gav Wood
i at gavwood.com
Tue Apr 8 03:18:08 CEST 2014
Hi,
I'm working to extending some functionality to be used by the
Javascript as part of a QWebView page. I need to be able to pass
around some non-QObject derived classes (actually a big-integer class)
as arguments & return types of the APIs I expose. This worked find
when doing something similar in QML/QtQuick. Is it going to be
possible here?
I've tried
qRegisterMetaType<NonQObjectType>("NonQObjectType");
and
Q_DECLARE_METATYPE(NonQObjectType)
But then given a class:
class ExposedAPI: QObject
{
Q_OBJECT
public:
Q_INVOKABLE NonQObjectType foo();
Q_INVOKABLE QString bar(NonQObjectType _t);
Q_INVOKABLE QString baz();
};
If I expose with:
addToJavaScriptWindowObject("api", new ExposedAPI, QWebFrame::ScriptOwnership);
then the JavaScript:
window.api.bar(window.api.foo())
does nothing whereas:
window.api.baz()
works as expected.
Gav
--
Never put down to incompetence that which can be adequately explained
by self-interest.
More information about the Interest
mailing list