QT中inherits()函数可 判断一个对象的类是不是从另外一个类继承而来

函数原型 bool QObject::inherits ( const char * lname ) const

//来自官方文档

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)
posted @ 2021-07-16 01:41  Azuki_op  阅读(1033)  评论(0)    收藏  举报