Your QObject needs to have Q_OBJECT in it, but aside from that that, it looks sane enough.
I've been using the same approach in https://codereview.qt-project.org/#change,72338 and it works like a charm there. cheers, Gunnar On 29 Apr 2014, at 16:03, Gav Wood <qtinter...@gavwood.com> wrote: > 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. > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest