[Interest] QtWebKit bridge wont convert JS Arrays to QVariant

equalsraf at gmx.com equalsraf at gmx.com
Wed Oct 16 19:44:30 CEST 2013


Hi,

I'm exposing an object and its methods to the javascript engine inside
QtWebkit using QWebFrame::addToJavaScriptWindowObject(). Since I wanted
to be able to pass most standard Javascript objects to a method I
declared its argument as a QVariant. But this does not seem to work for
arrays, instead I get an exception in Javascript

    Error: incompatible type of argument(s) in call to testFail(); candidates were
    testFail(QVariant))

Calling the testFail() method from javascript with a string, double or
object{} successfully passes a valid QVariant, but calling it with an
array of any kind fails.

Perhaps my assumption that Qt would convert the array to QVariant is
wrong() - that was my understanding from the docs - I'm not using any
JS types other than arrays/objects/doubles/strings/bool. Qt versions here
are 5.1.0 and 5.1.1 on Linux.

I've tried to address this by changing the argument type, but came no
closer to getting a solution that works for the basic primitive and
composite JS types. If I add a method that takes a QVariantList, it
would work for a list, but it would trigger ambiguity errors, and stop
working for other data types.

Here is a full example project where I'm testing this,

	https://gist.github.com/equalsraf/7005829

Any insights anyone can provide would be appreciated, Thanks,




More information about the Interest mailing list