Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWebView evaluatejavascript argument

QWebView evaluatejavascript argument

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sirvo
    wrote on 26 Jun 2013, 01:07 last edited by
    #1

    Hello,

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

    Ex.

    On Qt:

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

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

    @
    function hello(arg1) {
    alert(arg1);
    }
    @

    The call in the HTML file would be:

    @
    *something.getMessage(hello);
    @

    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?

    Thanks!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Serenity
      wrote on 26 Jun 2013, 06:20 last edited by
      #2

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

      1 Reply Last reply
      0
      • R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 26 Jun 2013, 06:21 last edited by
        #3

        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

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sirvo
          wrote on 26 Jun 2013, 11:02 last edited by
          #4

          Hum?

          I don't think you got it:

          @
          void Container::getEventInformation(const QString &eventId, const QString &callback)
          {
          // What it is now
          view->page()->mainFrame()->evaluateJavaScript(QString("eventResult('%1','%2')").arg(eventId).arg(eventId));

          // 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?

          1 Reply Last reply
          0

          1/4

          26 Jun 2013, 01:07

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved