Qt inherits

inherits()方法可以判断该控件是否是某个类的子类,有时很有用处。

    QPushButton *btn = new QPushButton;

    qDebug()<<"btn is inherits QAbstractButton? "<inherits("QAbstractButton");
    qDebug()<<"btn is inherits QWidget?"<inherits("QWidget");
    qDebug()<<"btn is inherits QObject?"<inherits("QObject");
    qDebug()<<"btn is inherits QPaintDevice?"<inherits("QPaintDevice");
    qDebug()<<"btn is inherits QTimer?"<inherits("QTimer");

你可能感兴趣的:(Qt)