Looking for Q_PLUGIN_METADATA explain.



  • @
    class BasicToolsPlugin : public QObject,
    public BrushInterface,
    public ShapeInterface,
    public FilterInterface
    {
    Q_OBJECT
    //! [4]
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.Examples.PlugAndPaint.BrushInterface" FILE "basictools.json")
    //! [4]
    Q_INTERFACES(BrushInterface ShapeInterface FilterInterface)
    @

    I want to know hot to setting Q_PLUGIN_METADATA'IID.
    At the code demo before, there is three interface (BrushInterface, ShapeInterface, FilterInterface);
    and the Q_PLUGIN_METADATA use the BrushInterface. So is that BrushInterface is the only choice for BasicToolsPlugin
    is there any reason for this choice?
    Why we needd to specify the Interface IID for Q_PLUGIN_METADATA, indeed, we can retrieve BrushInterface IID through
    from Q_INTERFACES(BrushInterface ShapeInterface FilterInterface).



  • Hi,

    The plugin IID has nothing todo with the INTERFACES IID.

    plugin IID is used to determine whether the plugin is your needed or not.

    while interface IID is used in qobject_cast().

    You can take a look at http://blog.debao.me/2013/06/qt-macro-q-declare-interface/



  • That's great, the misunderstanding comes from
    http://qt-project.org/doc/qt-5.1/qtcore/plugins-howto.html
    @
    class MyStylePlugin : public QStylePlugin
    {
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE mystyleplugin.json)
    public:
    QStyle *create(const QString &key);
    };
    @
    and

    @
    #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 hope that will be modified.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.