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
Forum Updated to NodeBB v4.3 + New Features

Problem evaluating javascript source with QWebView

Scheduled Pinned Locked Moved General and Desktop
qwebviewqobjectqwebframe
6 Posts 2 Posters 2.9k 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 7 Aug 2015, 08:26 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 7 Aug 2015, 08:52
    0
    • J Jelko
      7 Aug 2015, 08:26

      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 7 Aug 2015, 08:52 last edited by
      #2

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

      J 1 Reply Last reply 11 Aug 2015, 07:18
      0
      • J Offline
        J Offline
        Jelko
        wrote on 11 Aug 2015, 07:15 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
          7 Aug 2015, 08:52

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

          J Offline
          J Offline
          Jelko
          wrote on 11 Aug 2015, 07:18 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 11 Aug 2015, 16:30
          0
          • J Jelko
            11 Aug 2015, 07:18

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

            R Offline
            R Offline
            raf924
            wrote on 11 Aug 2015, 16:30 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 13 Aug 2015, 08:09 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

              1/6

              7 Aug 2015, 08:26

              • Login

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