3 ms·
Exactly. In the QML example, it sounds like some function is creating a QML form and passing in pointers to objects which are not copied but stored by QML (or
by projektfu 3y ago
Exactly. In the QML example, it sounds like some function is creating a QML form and passing in pointers to objects which are not copied but stored by QML (or Javascript). The form template is persistent and is reused when new windows are created, perhaps.
Another article on the author's site references a different complaint about QML, that it sometimes does assume ownership of objects, if they are normal QObjects without parents. This led to them getting reclaimed by the window being closed. There is, of course, documentation for when this might happen.
One thing that's generally true in C++ is that the user of a library has to play along. If the library wants to allocate your objects, let it. If it wants to take ownership of your objects, expect it. If it doesn't take ownership, you need to understand their lifetimes. It's definitely one of the frustrating things about C++, but I wouldn't expect a lot of complaints about one library or another unless they were being surprisingly capricious, taking ownership on Wednesday, not using your allocated objects on Friday, copying on Monday.