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

Problem evaluating javascript source with QWebView

Scheduled Pinned Locked Moved General and Desktop
qwebviewqobjectqwebframe
6 Posts 2 Posters 3.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.
  • J Offline
    J Offline
    Jelko
    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

    R 1 Reply Last reply
    0
    • J Jelko

      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

      R Offline
      R Offline
      raf924
      wrote on last edited by
      #2

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

      J 1 Reply Last reply
      0
      • J Offline
        J Offline
        Jelko
        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
        • R raf924

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

          J Offline
          J Offline
          Jelko
          wrote on last edited by
          #4

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

          R 1 Reply Last reply
          0
          • J Jelko

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

            R Offline
            R Offline
            raf924
            wrote on last edited by
            #5

            @Jelko

            if (Wizard_OnNext != null) {
             wizard.nextButtonClicked.connect(Wizard_OnNext);
            }
            
            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jelko
              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