Qt World Summit: Register Today!

QWebView evaluatejavascript argument

  • Hello,

    When using the evaluateJavaScript("someMethod()") in a QWebView, is it possible to use a callback instead of typing the method itself?


    On Qt:

    void getMessage(const QString &callback) {
    (...).evaluateJavaScript(callback(arg1, ...);

    The callback function would be one within a js file, ex.:

    function hello(arg1) {

    The call in the HTML file would be:


    As you see, the function called in the HTML file points the callback to the function Hello, but its arguments would come from Qt.

    I have to use callback instead of typing the method itself. Any tips?


  • looks more like a javascript problem and I think, there are no callbacks in Javascript.

  • Moderators

    since evaluateJavaScript() only takes 1 string as an argument how would that be possible?

    But if it helps you can compose javascript inside javascript and execute it using "eval(...)":http://www.w3schools.com/jsref/jsref_eval.asp

  • Hum?

    I don't think you got it:

    void Container::getEventInformation(const QString &eventId, const QString &callback)
    // What it is now

    // What I need: evaluate the callback function
    // view->page()->mainFrame()->evaluateJavaScript(callback('%1','%2')).arg(x).arg(y));

    To remember, callback is a javascript function.

    But, it does not work. The evaluateJavaScript (callback) does not execute the callback function. So, is there a way to make it work?

Log in to reply