As I understand, the following code is a perfectly fine way to create a QObject
QLabel *label = new QLabel("label");
QWidget window;
label->setParent(&window);
window.show();
As I am reading everywhere "the parent takes ownership of the newly created object - and eventually calls delete", or "the composite object takes ownership of the children so, as long as the parenting has been done, you can be assured that the child QObjects will be destroyed when the parent is destroyed" (from How does Qt delete objects ? And what is the best way to store QObjects?)
Can someone tell me how can Qt "take ownership" of a QObject? More technically: how is it possible for Qt (which is a library and has its own runtime) to call operator delete on a pointer I created with an operator new from a different runtime? Why doesn't it crash?
EDIT
I am adding this reference as the whole point of the question comes from this:
"The code running in the DLL might be using a different C++ runtime library, which means that the layout of the heap will be different. The DLL might be using a different heap altogether.
Calling delete (in the main program) on a pointer allocated by the DLL (or vice versa) will lead to (at best) an immediate crash or (at worst) memory corruption that'll take a while to track down." (from C++ mix new/delete between libs?)