[Qt-interest] How to discover if a custom type stored into a QVariant inherits the QObject class

Flavio Castelli flavio at castelli.name
Thu Mar 18 18:33:12 CET 2010


Is it possible to know at run-time if a custom type stored into a QVariant 
instance inherits the QObject class?

In the following example Person is a child of QObject:

  Person* p = new Person();

  QVariant v;
  v.setValue(p);
  qDebug() << v.canConvert<QObject*>(); // returns false
  qDebug() << v.typeName(); // return Person*
  qDebug() << QVariant::nameToType(v.typeName()); //return QVariant::UserType
  delete p;

Thanks in advance
Flavio



More information about the Qt-interest-old mailing list