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
Qt 6.11 is out! See what's new in the release blog

QWebView evaluatejavascript argument

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 4.4k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on 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
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on 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
        • ? Offline
          ? Offline
          A Former User
          wrote on 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

          • Login

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