[Qt-interest] addToJavaScriptWindowObject and javascript arguments object

michael.goddard at nokia.com michael.goddard at nokia.com
Fri Jul 24 02:17:21 CEST 2009


Hello Andrew,

> So the question is this: what C++ class should I use as the argument
> type in the object given to addToJavaScriptWindowObject() to match the
> JavaScript arguments object?

I'm not sure if the Arguments object can be converted directly to C++ (some objects get converted as a QVariantMap), but you can convert the arguments pseudo array to an actual array and pass it in as a QVariantList.

class TestObj : public QObject
{
    Q_OBJECT
public slots:
    void foo(QVariantList v)
    {
        qDebug() << "got list:" << v;
    }
};

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QWebView v;
    QWebFrame* f = v.page()->mainFrame();
    TestObj *testobj = new TestObj();

    f->addToJavaScriptWindowObject("testobj", testobj);
    f->evaluateJavaScript("function f() {testobj.foo(Array.prototype.slice.call(arguments));} f('one', 2, 3.0);");
    
    return 0;
}

Hope this helps.

Cheers,
MichaelG

--
Michael Goddard
Qt Software, Nokia



More information about the Qt-interest-old mailing list