Important: Please read the Qt Code of Conduct -

Qobject_cast and Q_DECLARE_INTERFACE

  • Nearby topic made me think that I don't understand something. qobject_cast documentation says that returned value it undefined if template argument doesn't inherit QObject. But interfaces don't inherit it though Plug & Paint example uses qobject_cast from QObject* to an interface.
    Is this an error in the documentation or did I miss something?

  • Hi,
    that is reason why you use Q_INTERFACES macro, it tells to metaObject that it is "qobject & your inteface" during qobject_cast.. without that macro, you will get null pointer from that cast .. it is in the doc

  • Yes, now I found the line which describes it. Multiple "Warning"s about Q_OBJECT confused me.

Log in to reply