[Interest] QJSValue as parameter to Q_INVOKABLE

Gav Wood qtinterest at gavwood.com
Thu May 1 14:28:14 CEST 2014


Yeah - Q_OBJECT makes no difference. I should have noted that I'm
wanting to integrate into the Javascript behind the QtWebkit stuff.

So notably a number of things work fine with Qt/JS integration for
QtQuick (as yours does) and not for QtWebkit:

Padding registered meta types around as values in JS is another thing
that works fine for the Javascript engine in QtQuick/QML and is
silently broken for the Javascript in QtWebkit.

I guess this is another one of those things.

Gav.

On 30 April 2014 07:27, Gunnar Sletta <gunnar.sletta at jolla.com> wrote:
> 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 <qtinterest at 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 at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>



More information about the Interest mailing list