IPlugin with Q_DECLARE_INTERFACE?
Unsolved
Qt Creator and other tools
-
I‘m reading Qt Creator's source code.
Documents says that definite of an interface class as below://header class FilterInterface { public: virtual ~FilterInterface() {} virtual QStringList filters() const = 0; virtual QImage filterImage(const QString &filter, const QImage &image, QWidget *parent) = 0; }; Q_DECLARE_INTERFACE(FilterInterface, "org.qt-project.Qt.Examples.PlugAndPaint.FilterInterface") //source #include <QObject> #include <QtPlugin> #include <QStringList> #include <QImage> #include <plugandpaint/interfaces.h> class ExtraFiltersPlugin : public QObject, public FilterInterface { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.Examples.PlugAndPaint.FilterInterface" FILE "extrafilters.json") Q_INTERFACES(FilterInterface) public: QStringList filters() const; QImage filterImage(const QString &filter, const QImage &image, QWidget *parent); };
I found many of writings like this in code.
However, other usage like IPlugin, IContext, IMode is also used.
Why IPlugin don't use Q_DECLARE_INTERFACE like above? -
@Hu-Junhao Because the plugin implements the interface, it does not declare an interface.
-
@jsulm IPlugin is the interface.
class EXTENSIONSYSTEM_EXPORT IPlugin : public QObject { Q_OBJECT //... } class HelloWorldPlugin : public ExtensionSystem::IPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "HelloWorld.json") //... }
why not
class IPlugin { public: virtual ~IPlugin() {} //... }; Q_DECLARE_INTERFACE(FilterInterface, "org.qt-project.Qt.QtCreatorPlugin") class HelloWorldPlugin : public QObject, public ExtensionSystem::IPlugin { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "HelloWorld.json") Q_INTERFACES(IPlugin) //... }
maybe IPlugin has a signal?