title: Is it valid to call QJSEngine::newQObject() in a C++ function called by a script?
body: <p>Consider this example:</p>
  <p><code>ObjectCreator</code> is set as global property via <code>QJSEngine</code>:</p>
  <pre class="lang-cpp prettyprint-override"><code>// ObjectCreator is exposed to engine_ env as global property
  class ObjectCreator : public QObject
  {
      Q_OBJECT
  
  public:
      ObjectCreator(QJSEngine * engine, QObject * parent = nullptr) : QObject(parent), engine_(engine) {}
      
      // Called from script env
      Q_INVOKABLE QJSValue createObject();
  
  private:
      
      // engine_ is not owned
      QJSEngine * engine_ = nullptr;
  };
  
  class SomeObj : public QObject
  {
      // ...
  };
  
  QJSValue ObjectCreator::createObject()
  {
      // No parent due to JavaScriptOwnership
      return engine_-&gt;newQObject(new SomeObj());
  }
  </code></pre>
  <p>JavaScript (evaluated in <code>engine_</code> from previous snippet):</p>
  <pre class="lang-js prettyprint-override"><code>function f
  {
          // objectCreator is a global property of engine_
          const someObj = objectCreator.createObj();
  }
  </code></pre>
  <p>Reading the <a href="https://doc.qt.io/qt-5/qjsengine.html#newQObject" rel="nofollow noreferrer">documentation</a> I couldn't find an answer to this question:</p>
  <p>Is it valid to call <code>engine_-&gt;newQObject()</code> in a C++ function that is invoked via a JavaScript-script that is evaluated by <code>engine_</code>?</p>