Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. IPlugin with Q_DECLARE_INTERFACE?
Forum Updated to NodeBB v4.3 + New Features

IPlugin with Q_DECLARE_INTERFACE?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
3 Posts 2 Posters 341 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hu Junhao
    wrote on last edited by
    #1

    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?

    jsulmJ 1 Reply Last reply
    0
    • H Hu Junhao

      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?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Hu-Junhao Because the plugin implements the interface, it does not declare an interface.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      H 1 Reply Last reply
      0
      • jsulmJ jsulm

        @Hu-Junhao Because the plugin implements the interface, it does not declare an interface.

        H Offline
        H Offline
        Hu Junhao
        wrote on last edited by
        #3

        @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?

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved