Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

const qobject_cast for interfaces



  • I like to use Q_DECLARE_INTERFACE, because it allows me to use qobject_cast for these interfaces (provided the implementation has the Q_INTERFACES makro)

    All works well, until I try to cast a const instance.

    So this works:
    ISomeInterface* pInterface = qobject_cast<ISomeInterface*>(pSomeObject);

    And this doesn't:
    const ISomeInterface* pInterface = qobject_cast<const ISomeInterface*>(pSomeObject);

    Error message is:
    'const class ISomeInterface' has no member named 'qt_check_for_QOBJECT_macro'
    'const class ISomeInterface' has no member named 'qt_check_for_QOBJECT_macro'

    Any ideas?