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

Cannot return a null object back to QML from a Q_INVOKABLE method

    XMLWordPrintable

Details

    • 3b3ec6bc4114db82462eef812a47db420d4505c2

    Description

      Consider a Q_INVOKABLE method in an item defined in a plugin that returns a QObject pointer:

      Q_INVOKABLE QObject *fetchObject(int arg);
      

      If the function returns a non-null object then everything is happy and the QObject can be used in the normal JavaScript/QML way. However, if the function returns null (e.g. because the argument refers to a non-existent entity), then a crash will occur every time deep inside JSC. The attached example shows the problem.

      This particular pattern is needed in several places in Qt/3D:

      • Fetching a named material from a mesh.
      • Asking for the object that is under a specific mouse position using 3D object picking.
      • etc

      My expectation was that returning a null from C++ should result in the JavaScript "null" or "undefined" value, not a segfault.

      Attachments

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

        Activity

          People

            rweather Rhys Weatherley (closed Nokia identity) (Inactive)
            rweather Rhys Weatherley (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes