Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with Plugin Marcos: Error on Constructor Argument Count
Forum Updated to NodeBB v4.3 + New Features

Problem with Plugin Marcos: Error on Constructor Argument Count

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.1k Views 1 Watching
  • 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.
  • ModelTechM Offline
    ModelTechM Offline
    ModelTech
    wrote on last edited by ModelTech
    #1

    I am trying to make my application customizable by enabling the creation of plugins. I am using the Plug & Paint example as basis, but I am experiencing a build problem that refers to the expansion of Qt macros. I do not see what I should change to fix it. Hopefully somebody can help. The build error is the following and complains about the number of arguments for the constructor.

    moc_sdf3import.cpp:9: from moc_sdf3import.cpp:9:
    moc_sdf3import.cpp:-1: In function ‘QObject* qt_plugin_instance()’:
    moc_sdf3import.cpp:157: error: no matching function for call to ‘DFM::SDF3Import::SDF3Import()’
     QT_MOC_EXPORT_PLUGIN(DFM::SDF3Import, SDF3Import)
                               ^
    Qt5.7/5.7/gcc_64/include/QtCore/qplugin.h:112: in definition of macro ‘Q_PLUGIN_INSTANCE’
                     _instance = new IMPLEMENTATION; \
                                     ^
    moc_sdf3import.cpp:157: in expansion of macro ‘QT_MOC_EXPORT_PLUGIN’
     QT_MOC_EXPORT_PLUGIN(DFM::SDF3Import, SDF3Import)
     ^
    moc_sdf3import.cpp:9: In file included from moc_sdf3import.cpp:9:0:
    sdf3import.h:17: candidate: DFM::SDF3Import::SDF3Import(DFM::Model*, QFile*)
         explicit SDF3Import(Model *, QFile *);
                  ^
    sdf3import.h:17: note:   candidate expects 2 arguments, 0 provided
    

    To enable your help, here are some of the classes that I am using for this. First is a base Interface class (interface.h) from which I derive a number of Plugin Interfaces:

    #include <QDialog>
    #include "../model/model.h"
    
    namespace DFM {
    
    class Interface {
    public:
        explicit Interface(Model *S);
        virtual ~Interface() { }
        virtual const QString name() = 0;
        virtual const QVersionNumber version() = 0;
        QDialog *preDialog();
        void preProcess();
        QDialog *postDialog();
        void postProcess();
    protected:
        Model* Specification;
    };
    
    }
    

    The header file (importer.h) of the derived interface class that is relevant for this sdf3import.cpp class is as follows:

    #include <QtPlugin>
    #include <QFile>
    #include "interface.h"
    #include "../base/issue.h"
    
    namespace DFM {
    
    class DFMCORESHARED_EXPORT Importer : public Interface {
    
    public:
        explicit Importer(Model *, QFile *);
        virtual ~Importer();
        bool hasIssues();
        bool hasErrors();
        virtual void read() = 0;
        QList<Issue *> &issues();
    protected:
        QList<Issue *> Issues;
        QFile *File;
    };
    
    }
    
    #define ImportInterface_ID "AUniqueString.ImportInterface"
    Q_DECLARE_INTERFACE(DFM::Importer, ImportInterface_ID)
    

    These complete the part of my dfmcore library. Now, I use these to create a plugin in a different project. The sdf3import.h file looks as follows:

    #include <dfmcore.h>
    
    namespace DFM {
    
    class SDF3Import : public QObject, public Importer {
        Q_OBJECT
        Q_PLUGIN_METADATA(IID "AUniqueString.ImportInterface")
        Q_INTERFACES(DFM::Importer)
    
    public:
        explicit SDF3Import(Model *, QFile *);
        const QString name() override;
        const QVersionNumber version() override;
        void read() override;
        QDialog *postDialog();
        void postProcess();
    };
    
    }
    

    The sdf3import.cpp file is not at all interesting, but to be sure, here is a part of the constructor:

    SDF3Import::SDF3Import(Model *S, QFile *F) : QObject(), Importer(S, F) { }
    
    jsulmJ 1 Reply Last reply
    0
    • ModelTechM ModelTech

      I am trying to make my application customizable by enabling the creation of plugins. I am using the Plug & Paint example as basis, but I am experiencing a build problem that refers to the expansion of Qt macros. I do not see what I should change to fix it. Hopefully somebody can help. The build error is the following and complains about the number of arguments for the constructor.

      moc_sdf3import.cpp:9: from moc_sdf3import.cpp:9:
      moc_sdf3import.cpp:-1: In function ‘QObject* qt_plugin_instance()’:
      moc_sdf3import.cpp:157: error: no matching function for call to ‘DFM::SDF3Import::SDF3Import()’
       QT_MOC_EXPORT_PLUGIN(DFM::SDF3Import, SDF3Import)
                                 ^
      Qt5.7/5.7/gcc_64/include/QtCore/qplugin.h:112: in definition of macro ‘Q_PLUGIN_INSTANCE’
                       _instance = new IMPLEMENTATION; \
                                       ^
      moc_sdf3import.cpp:157: in expansion of macro ‘QT_MOC_EXPORT_PLUGIN’
       QT_MOC_EXPORT_PLUGIN(DFM::SDF3Import, SDF3Import)
       ^
      moc_sdf3import.cpp:9: In file included from moc_sdf3import.cpp:9:0:
      sdf3import.h:17: candidate: DFM::SDF3Import::SDF3Import(DFM::Model*, QFile*)
           explicit SDF3Import(Model *, QFile *);
                    ^
      sdf3import.h:17: note:   candidate expects 2 arguments, 0 provided
      

      To enable your help, here are some of the classes that I am using for this. First is a base Interface class (interface.h) from which I derive a number of Plugin Interfaces:

      #include <QDialog>
      #include "../model/model.h"
      
      namespace DFM {
      
      class Interface {
      public:
          explicit Interface(Model *S);
          virtual ~Interface() { }
          virtual const QString name() = 0;
          virtual const QVersionNumber version() = 0;
          QDialog *preDialog();
          void preProcess();
          QDialog *postDialog();
          void postProcess();
      protected:
          Model* Specification;
      };
      
      }
      

      The header file (importer.h) of the derived interface class that is relevant for this sdf3import.cpp class is as follows:

      #include <QtPlugin>
      #include <QFile>
      #include "interface.h"
      #include "../base/issue.h"
      
      namespace DFM {
      
      class DFMCORESHARED_EXPORT Importer : public Interface {
      
      public:
          explicit Importer(Model *, QFile *);
          virtual ~Importer();
          bool hasIssues();
          bool hasErrors();
          virtual void read() = 0;
          QList<Issue *> &issues();
      protected:
          QList<Issue *> Issues;
          QFile *File;
      };
      
      }
      
      #define ImportInterface_ID "AUniqueString.ImportInterface"
      Q_DECLARE_INTERFACE(DFM::Importer, ImportInterface_ID)
      

      These complete the part of my dfmcore library. Now, I use these to create a plugin in a different project. The sdf3import.h file looks as follows:

      #include <dfmcore.h>
      
      namespace DFM {
      
      class SDF3Import : public QObject, public Importer {
          Q_OBJECT
          Q_PLUGIN_METADATA(IID "AUniqueString.ImportInterface")
          Q_INTERFACES(DFM::Importer)
      
      public:
          explicit SDF3Import(Model *, QFile *);
          const QString name() override;
          const QVersionNumber version() override;
          void read() override;
          QDialog *postDialog();
          void postProcess();
      };
      
      }
      

      The sdf3import.cpp file is not at all interesting, but to be sure, here is a part of the constructor:

      SDF3Import::SDF3Import(Model *S, QFile *F) : QObject(), Importer(S, F) { }
      
      jsulmJ Online
      jsulmJ Online
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @ModelTech said in Problem with Plugin Marcos: Error on Constructor Argument Count:

      explicit SDF3Import(Model *, QFile *);

      You don't have default constructor.

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

      1 Reply Last reply
      0
      • ModelTechM Offline
        ModelTechM Offline
        ModelTech
        wrote on last edited by ModelTech
        #3

        Do you mean that I must also have a constructor with 0 arguments like in

        explicit SDF3Import(Model * = NULL, QFile* = NULL)
        

        Well, I have tried this and it does solve the build issue. But how can I avoid this default with 0 arguments (I would like to do so...)

        1 Reply Last reply
        0
        • ModelTechM Offline
          ModelTechM Offline
          ModelTech
          wrote on last edited by
          #4

          Now that I got it to work, I discovered how it actually works and that I shouldn't use those arguments to the constructor at all. Instead, I should have such arguments to the methods that I want for the interface: The interface object is always created at loading the plugin (which is not what I anticipated...) So, problem solved!

          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