PDA

View Full Version : Getting Type of an variable



hgedek
9th September 2007, 16:30
How can I find which type of my variable?Is there a pratical way?EX.QComboBox *combo;
type(combo)==QComboBox mean;

marcel
9th September 2007, 16:37
If you want type information about non-Qt objects you will have to use some reflection mechanism(there are a few libraries available).

For Qt objects, you have QObject::inherits (http://doc.trolltech.com/latest/qobject.html#inherits) and QMetaObject::className (http://doc.trolltech.com/latest/qmetaobject.html#className) and QMetaObject::superClass (http://doc.trolltech.com/latest/qmetaobject.html#superClass).

Or you can use dynamic_cast:


if(dynamic_cast<QComboBox*>(combo) != null)
// do someyhing

Note in this case you need a pointer to QComboBox.

Regards