diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 8024c973732..4f764e7e784 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -363,14 +363,7 @@ QObject *QMetaObject::cast(QObject *obj) const */ const QObject *QMetaObject::cast(const QObject *obj) const { - if (obj) { - const QMetaObject *m = obj->metaObject(); - do { - if (m == this) - return obj; - } while ((m = m->d.superdata)); - } - return 0; + return (obj && obj->metaObject()->inherits(this)) ? obj : nullptr; } #ifndef QT_NO_TRANSLATION