Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-83432

QJSEngine missing QJSEngine::ConsoleExtension

    XMLWordPrintable

Details

    • macOS

    Description

      I am using QJSEngine, here is my access method from my helper class:

              QJSEngine* clsScriptHelper::pobjGetScriptEng() {
      
                  if ( clsScriptHelper::mspobjJSeng == nullptr )  {
                      clsScriptHelper::mspobjJSeng = new QJSEngine();
      
                      if ( clsScriptHelper::mspobjJSeng != nullptr ) {
      
                          clsScriptHelper::mspobjJSeng->installExtensions(QJSEngine::AllExtensions); //Added the tests below to illustrate it doesn't work, both error with 2
      
                          QJSValue err; err = clsScriptHelper::mspobjJSeng->evaluate("(print(1 + 2);)");
      
                          if ( err.isError() ) {
      
                              qDebug() << err.EvalError;
      
                          }
      
                          err = clsScriptHelper::mspobjJSeng->evaluate("(console.log(1 + 2);");
      
                          if ( err.isError() ) {
                              qDebug() << err.EvalError;
                          }
      
      //End of example tests proving it doesn't work!
      
                      }
                  }
                  Q_ASSERT_X(clsScriptHelper::mspobjJSeng!=nullptr, "clsScriptHelper::pobjGetScriptEnd", "mspobjJSeng is NULL!");
      
                  return clsScriptHelper::mspobjJSeng;
              }
      

      I've checked using the debugger and the call to InstallExtensions is getting called. However when I call evaluate on a script to be processed I get error number 2 returned.

      According to the documentation this:

              Indicates that console functions (console.log(), for example) should be installed.

      Why am I getting this, doesn't QJSEngine::AllExtensions include

      QJSEngine::ConsoleExtension ?

      Even if I add QJSEngine::ConsoleExtension to the InstallExtensions call I still get the same error.

      From: https://doc.qt.io/qt-5.9/qjsengine.html

      QJSEngine::ConsoleExtension 0x2 Indicates that console functions (console.log(), for example) should be installed.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            simonplatten Simon Platten
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes