PDA

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



Jeffb
17th April 2012, 07: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?

Thanks
Jeff

kito
17th April 2012, 08: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.

ChrisW67
17th April 2012, 09: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();
}