Problem with Plugin Marcos: Error on Constructor Argument Count



  • 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) { }
    

  • Moderators

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

    explicit SDF3Import(Model *, QFile *);

    You don't have default constructor.



  • 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...)



  • 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!


Log in to reply