-
Bug
-
Resolution: Fixed
-
P3: Somewhat important
-
5.1.1
-
None
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.