PDA

View Full Version : Print out graphics item type information



sajis997
23rd January 2012, 20:40
Hello forum,

I am having issues while printing out the graphics item type information. I want to print the verbose information not the numeric one.

Is there any mechanism in Qt to print the graphics item type, something like the following:





qDebug () << "Item type: " << item->type() << endl;




The above code gives me the numeric value, i would like to have something verbose


Regards
Sajjad

stampede
23rd January 2012, 20:53
You can use the typeid (https://secure.wikimedia.org/wikipedia/en/wiki/Typeid) operator to print the class name of any object:


#include <QApplication>
#include <QtCore>
#include <QDebug>
#include <QtGui>
#include <typeinfo>

class MyClass
{
};

int main(int argc, char **argv) {

QGraphicsLineItem line;
QGraphicsRectItem rect;
QApplication app(argc,argv);
MyClass m;

qDebug() << typeid(line).name() << typeid(rect).name();
qDebug() << typeid(app).name() << typeid(m).name();

return 0;
}


remember to #include <typeinfo>. The output depends on the compiler, so use this carefully (don't make any assumptions about this value, just use it for your information only):


17QGraphicsLineItem 17QGraphicsRectItem
12QApplication 7MyClass