View Full Version : Output the address of an object i.e. a pointer?

17th April 2012, 08:14
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?


17th April 2012, 09:45
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.

17th April 2012, 10:04
This is, of course, only for developer consumption.

qDebug() << aNodePtr;
0x2197f50 // for a non-QObject
JB_Node(0x2197f50) // if JB_Node is a QObject

works fine here. You can even provide your own operator<<() to format it however you want:

QDebug operator<<(QDebug dbg, JB_Node *node) {
dbg.nospace() << QString("Custom format [addr = %1 ]").arg(quintptr(node), 0, 16);
return dbg.space();