In QDBus example, new QDBusAbstractAdaptor without keeping pointer, why?

  • I am reading QDBus example code here,, 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.

  • Qt Champions 2017

    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 new anywhere. It's parented so it won't leak memory, and it probably does all the needed QObject::connect calls (or similar initializations) in its constructor.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.