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

QQmlType::SingletonInstanceInfo::destroy() tries to delete singletons not on heap

XMLWordPrintable

      Edit: Comment thread summary is that the singleton should probably return QmlOwnership (and have "undefined" behavior if cpp ownership is set)

      When QQmlEngine is destroyed, all singletons are deleted, even if they aren't in the heap. This makes it impossible to use the standard C++ programming pattern of storing a singleton as a static variable in a function.

      Overall, the handling of "singletons" by QML is misleading at best. They are not really singletons in the way programmers usually think. They are handled inconsistently and are not available in all contexts where QML code can be evaluated. In this specific case, they also break documented behavior.

      The ownership of a singleton is CppOwnership. The documentation says "The object is owned by C++ code, and will never be deleted by QML." One should be able to count on that.

      The attached code gives a minimal example of the problem.

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

            ulherman Ulf Hermann
            topiolli Topi Mäenpää
            Votes:
            4 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes