Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. In QDBus example, new QDBusAbstractAdaptor without keeping pointer, why?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 526 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FloatFlower.Huang
    wrote on last edited by
    #1

    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.

    kshegunovK 1 Reply Last reply
    0
    • F FloatFlower.Huang

      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.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      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.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved