Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. object address
Forum Updated to NodeBB v4.3 + New Features

object address

Scheduled Pinned Locked Moved Solved C++ Gurus
4 Posts 3 Posters 1.6k 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.
  • O Offline
    O Offline
    ODБOï
    wrote on 23 Jan 2020, 16:25 last edited by aha_1980
    #1

    Hello,
    sorry for this 2 stupid questions, i could not find information on this by my self.

       QObject * obj;
       obj = new QObject();
       qDebug() << "obj  : " << obj;
       qDebug() << "obj adr  : " << &obj;
    
    //output
    //obj  :  QObject(0x2532b60)
    //obj adr :  0x65fd48
    

    what is the 0x2532b60 ? i always tought it is the object adress.

    second question is : If i look at qdebug operator << https://doc.qt.io/qt-5/qdebug.html#public-functions
    i don't understand witch one is used when i call,

    qDebug() << obj;
    

    is it the last one "operator<<(const void *t)" ?
    Thank you

    K 1 Reply Last reply 23 Jan 2020, 17:42
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 23 Jan 2020, 16:47 last edited by
      #2

      @LeLev said in object adress:

      what is the 0x2532b60 ? i always tought it is the object adress.

      &obj

      since obj is a pointer, you see the address of the pointer

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      5
      • O ODБOï
        23 Jan 2020, 16:25

        Hello,
        sorry for this 2 stupid questions, i could not find information on this by my self.

           QObject * obj;
           obj = new QObject();
           qDebug() << "obj  : " << obj;
           qDebug() << "obj adr  : " << &obj;
        
        //output
        //obj  :  QObject(0x2532b60)
        //obj adr :  0x65fd48
        

        what is the 0x2532b60 ? i always tought it is the object adress.

        second question is : If i look at qdebug operator << https://doc.qt.io/qt-5/qdebug.html#public-functions
        i don't understand witch one is used when i call,

        qDebug() << obj;
        

        is it the last one "operator<<(const void *t)" ?
        Thank you

        K Offline
        K Offline
        Konstantin Tokarev
        wrote on 23 Jan 2020, 17:42 last edited by
        #3

        @LeLev said in object adress:

        what is the 0x2532b60 ? i always tought it is the object adress.

        0x2532b60 is the address of QObject, which is allocated in heap by operator new.

        0x65fd48 is the address of obj variable of type QObject*, which is allocated on stack and holds address of QObject object.

        second question is : If i look at qdebug operator << https://doc.qt.io/qt-5/qdebug.html#public-functions
        i don't understand witch one is used when i call,

        qDebug() << obj;
        

        is it the last one "operator<<(const void *t)" ?

        No, it's QDebug operator<<(QDebug, const QObject *). Overload for void* pointers prints just value without "QObject(...)" wrapping

        1 Reply Last reply
        5
        • O Offline
          O Offline
          ODБOï
          wrote on 23 Jan 2020, 18:07 last edited by
          #4

          @Christian-Ehrlicher, @Konstantin-Tokarev
          thank you very much for your inputs.

          1 Reply Last reply
          1

          1/4

          23 Jan 2020, 16:25

          • Login

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