Results 1 to 3 of 3

Thread: Output the address of an object i.e. a pointer?

  1. #1
    Join Date
    Apr 2010
    Posts
    77
    Thanks
    10
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Output the address of an object i.e. a pointer?

    Hi Guys

    What's the best way to output the address of an object e.g. JB_Node* aNodePtr;
    How do I output the value of aNodePtr?

    Thanks
    Jeff

  2. #2
    Join Date
    Mar 2012
    Location
    Lesotho
    Posts
    33
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Output the address of an object i.e. a pointer?

    A pointer must have a values,And to me it seems like JB_Node is a class so it must have member functions and attrubutes.it depends which value you are looking for.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Output the address of an object i.e. a pointer?

    This is, of course, only for developer consumption.
    Qt Code:
    1. qDebug() << aNodePtr;
    2. 0x2197f50 // for a non-QObject
    3. JB_Node(0x2197f50) // if JB_Node is a QObject
    To copy to clipboard, switch view to plain text mode 
    works fine here. You can even provide your own operator<<() to format it however you want:
    Qt Code:
    1. QDebug operator<<(QDebug dbg, JB_Node *node) {
    2. dbg.nospace() << QString("Custom format [addr = %1 ]").arg(quintptr(node), 0, 16);
    3. return dbg.space();
    4. }
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to ChrisW67 for this useful post:

    Jeffb (17th April 2012)

Similar Threads

  1. display pointer memory address
    By milosav in forum Qt Programming
    Replies: 8
    Last Post: 2nd February 2016, 09:54
  2. Help with Q_PROPERTY with object pointer
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 18:31
  3. static Object Vs Pointer
    By rajeshs in forum General Programming
    Replies: 4
    Last Post: 11th June 2008, 08:41
  4. Saving object pointer
    By MarkoSan in forum General Programming
    Replies: 4
    Last Post: 11th January 2008, 12:53
  5. Pointer to ActiveX object in QT
    By json84 in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2007, 13:42

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.