Important: Please read the Qt Code of Conduct -

Problem evaluating javascript source with QWebView

  • 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)

    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 Have you tried putting brackets around the connect line?

  • 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

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

  • @Jelko

    if (Wizard_OnNext != null) {

  • It now works:

    QString scriptSource = "if (typeof Wizard_OnNext == 'function') { wizard.nextButtonClicked.connect(Wizard_OnNext); }";