Hi Etienne, there are two requirements:
1. The interface must be pure virtual (so it cannot derive from QObject) 2. qobject_cast requires a QObject subclass Hence, your plugin implementation must inherit from both. The implementation itself can derive from QObject but the interface cannot. The main question here is if you want to use signal/slots with your plugin. Since the interface is pure virtual there is no chance to connect a signal or slot to it. I therefore introduced a factory pattern in my implementations: class IFactory { public: //! \brief Virtual destructor virtual ~IFactory() {} virtual IPluginObject *create(QObject *parent = nullptr) = 0; }; class Q_DECL_EXPORT CFactory : public QObject, public IFactory { Q_OBJECT Q_PLUGIN_METADATA(IID "your.interface.name") Q_INTERFACES(IFactory) public: virtual IPluginObject *create(QObject *parent) override; }; class IPluginObject : public QObject { public: //! \brief Virtual destructor virtual ~IPluginObject() {} public slots: void someSlot () = 0; signals: void someSignal() {} = 0; }; As you can see only the factory is exported as a pure virtual interface. Your real plugin object interface is subclassing QObject. I usually implement all plugins way as long as I'm 100 % sure I never going to use signal/slots. Hope that helps a bit. Roland 2014-05-22 9:55 GMT+02:00 Samuel Stirtzel <s.stirt...@googlemail.com>: > 2014-05-22 9:37 GMT+02:00 Etienne Sandré-Chardonnal < > etienne.san...@m4x.org>: > > Dear all, > > > > I'm reading the doc in order to implement plugins into my Qt 4.8 > > application. > > > > The manual says that I need first to define the plugin interface as a > pure > > virtual class. In the example it does not inherit QObject. > > > > Then it shows an example plugin implementation which inherits from > QObject > > and the interface class (multiple inheritance) > > > > Then it says "use qobject_cast() to test whether a plugin implement a > given > > interface". However, the qobject_cast page clearly says that the target > > class type must inherit QObject. > > > > I dit not try compiling an example yet, but how could this work? > Shouldn't > > the interface inherit QObject, and the plugin implementation simply > inherit > > the interface class? > > > > Hi, > > look up the Q_DECLARE_INTERFACE macro definition. > > The docs describe this as "Use the Q_DECLARE_INTERFACE() macro to tell > Qt's meta-object system about the interface." > > > -- > Regards > Samuel > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest >
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest