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

Allow Q_INVOKABLE Constructors to Throw Exceptions in QJSEngine

    XMLWordPrintable

Details

    Description

      When calling the constructor of a C++ class from within JS, it would be nice if the constructor could throw JS exceptions. Because the invoking engine instance is not known at creation time of the object, ugly workarounds like storing the engine in a global variable are needed.

      Suggestion 1:

      • a factory function parameter in QJSEngine::newQMetaObject() which takes QJSEngine as parameter and which would create the C++ object instead. Just like C++ singletons are created by QQmlEngine.
      • The factory function should take QJSValueList as parameter in order to call an appropriate constructor

      Suggestion 2:

      • make QJSEngine* a required first parameter for invokable constructors

      Attachments

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

        Activity

          People

            qtqmlteam Qt Qml Team User
            rweickelt Richard Weickelt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes