[Interest] QJSValue as parameter to Q_INVOKABLE

Gav Wood qtinterest at gavwood.com
Tue Apr 29 16:03:31 CEST 2014


Hi,

I'd like to expose an API within a QJSEngine JavaScript environment
for an asynchronous callback.

Thus I want to expose a method "regCallback":

foo.regCallback(function() { alert("Hello"); })

and allow C++ to call that function at some later point. The function
is exposed as a QJSValue, thus I'd expect a class Foo to look
something like this:

class Foo: public QObject
{
public:
  Q_INVOKABLE void regCallback(QJSValue someFunction) { m_f = someFunction; }
  void doCallback() { m_f.call(); }

private:
  QJSValue m_f;
};

However this doesn't work; regCallback never gets called. Is there
some other way to achieve this API?

Gav.



More information about the Interest mailing list