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. Problem evaluating javascript source with QWebView
Qt 6.11 is out! See what's new in the release blog

Problem evaluating javascript source with QWebView

Scheduled Pinned Locked Moved General and Desktop
qwebviewqobjectqwebframe
6 Posts 2 Posters 4.5k 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

    Hi,

    I could use some help solving the following problem. I keep getting an error with the following code:
    // HtmlWizard.cpp
    QString scriptSource = "if (Wizard_OnNext != null)
    wizard.nextButtonClicked.connect(Wizard_OnNext);";
    ui.webView->page()->mainFrame()->evaluateJavaScript(scriptSource);

    Here I try to execute some javascriptcode with the function evaluateJavascript, it should never give an error. However when the javascript function Wizard_OnNext does not exist,
    Qt shows an alert with the error:
    "undefined:1: ReferenceError: Can't find variable: Wizard_OnNext"

    This is incorrect, since the syntax is correct. Does anybody know how I can solve this problem?

    Thanks in advance,

    Jelko

    ? 1 Reply Last reply
    0
    • ? A Former User

      Hi,

      I could use some help solving the following problem. I keep getting an error with the following code:
      // HtmlWizard.cpp
      QString scriptSource = "if (Wizard_OnNext != null)
      wizard.nextButtonClicked.connect(Wizard_OnNext);";
      ui.webView->page()->mainFrame()->evaluateJavaScript(scriptSource);

      Here I try to execute some javascriptcode with the function evaluateJavascript, it should never give an error. However when the javascript function Wizard_OnNext does not exist,
      Qt shows an alert with the error:
      "undefined:1: ReferenceError: Can't find variable: Wizard_OnNext"

      This is incorrect, since the syntax is correct. Does anybody know how I can solve this problem?

      Thanks in advance,

      Jelko

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @Jelko Have you tried putting brackets around the connect line?

      ? 1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        I try to use standard javascript code to determine if a function exists, it seems
        that the Qt engine which parses javascript does not recognize it as valid javascript code. Does somebody know a workaround?

        Thanks in advance

        1 Reply Last reply
        0
        • ? A Former User

          @Jelko Have you tried putting brackets around the connect line?

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          @raf924 I am not sure what you mean: I tried different combinations. Could you give an example?

          ? 1 Reply Last reply
          0
          • ? A Former User

            @raf924 I am not sure what you mean: I tried different combinations. Could you give an example?

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @Jelko

            if (Wizard_OnNext != null) {
             wizard.nextButtonClicked.connect(Wizard_OnNext);
            }
            
            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              It now works:

              QString scriptSource = "if (typeof Wizard_OnNext == 'function') { wizard.nextButtonClicked.connect(Wizard_OnNext); }";
              ui.webView->page()->mainFrame()->evaluateJavaScript(scriptSource);

              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