根据qt5帮助文档,
bool QObject::inherits(const char * className) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.
返回真,如果对象是指定的继承类或QObject类的子类的一个实例,就返真.否则返回甲.
Example:
QTimer *timer = new QTimer; // QTimer inherits QObject
timer->inherits("QTimer"); // returns true
timer->inherits("QObject"); // returns true
timer->inherits("QAbstractButton"); // returns false
// QVBoxLayout inherits QObject and QLayoutItem
QVBoxLayout *layout = new QVBoxLayout;
layout->inherits("QObject"); // returns true
layout->inherits("QLayoutItem"); // returns true (even though QLayoutItem is not a QObject)
如果您需要确定对象是否为特定类的实例, 建议用 qobject_cast<Type *>(object) 代替.
See also metaObject() and qobject_cast().