In QDBus example, new QDBusAbstractAdaptor without keeping pointer, why?
I am reading QDBus example code here, http://doc.qt.io/qt-5/qtdbus-chat-chat-cpp.html, and I have a question.
At line 71:
// add our D-Bus interface and connect to D-Bus new ChatAdaptor(this); QDBusConnection::sessionBus().registerObject("/", this);
In this code, this example new a ChatAdaptor but not use lvalue to keep the pointer. In my opinion, this object will be "new" into memory heap, and if we don't keep the pointer, we will never know where is the object we "new".
My question is that how QDBusAbstractAdaptor do in our code, and why we don't need to keep the pointer of this object.
It's a custom class that you doesn't need after creating the actual obejct. That's why there's no assignment of the result from the
newanywhere. It's parented so it won't leak memory, and it probably does all the needed
QObject::connectcalls (or similar initializations) in its constructor.