Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problems loading plugins



  • Hi,

    I have several plugins that are subclasses of an abstract class. Interface class exists and is declared in abstract base class.
    Plugin_Metadata macro is used in the final plugin class.

    I followed plug_and_paint example with the difference, that I have an abstract class between interface and plugin.

    Building succeeds without errors, but when I run the app, no plugin is loaded.

    Debugging the app shows some error message like:

    undefined symbol: _ZNK20AbstractCenterWidget10metaObjectEv)"
    

    which is the abstract class, where I declared the interface-usage.

    Following the error, I added the plugin_metadata macro to the abstract class as well, but now compilation fails as moc tries to create an instance from that abstract class, which of cause will fail.

    How can I break that tangle?



  • @django-Reinhard Too hard say something without your code. Please show declaration of your class and how you load plugin and create instance of your object



  • Well, here we go:

    first the interface:

    #include <QtPlugin>
    
    QT_BEGIN_NAMESPACE
    class QWidget;
    class QCloseEvent;
    class QShowEvent;
    QT_END_NAMESPACE
    
    
    class PluginPageInterface
    {
    public:
      virtual ~PluginPageInterface() = default;
    
      virtual void closeEvent(QCloseEvent* e) = 0;
      virtual void showEvent(QShowEvent* e) = 0;
    
      virtual QWidget* createContent() = 0;
      virtual void connectSignals() = 0;
      virtual void updateStyles()   = 0;
      };
    
    QT_BEGIN_NAMESPACE
    #define PluginPageInterface_iid "de.schwarzrot.FalconView.PluginPage/0.1"
    Q_DECLARE_INTERFACE(PluginPageInterface, PluginPageInterface_iid)
    QT_END_NAMESPACE
    

    the abstract class declaration:

    #include <QWidget>
    #include <PluginPageInterface.h>
    
    QT_BEGIN_NAMESPACE
    class CenterView;
    class SettingsNotebook;
    class QString;
    class QAction;
    class QFile;
    QT_END_NAMESPACE
    
    
    /*! loads widgets from uiFile and allows late initialization at page usage
     */
    class AbstractCenterWidget : public QWidget, public PluginPageInterface
    {
      Q_OBJECT
      Q_INTERFACES(PluginPageInterface)
    public:
      void     initialize(const QString& fileName, const QString& name, bool addScrollArea = false);
      QAction* viewAction();
    
      // called by central widget stack
      virtual void closeEvent(QCloseEvent* e) override;
      virtual void showEvent(QShowEvent* e) override;
    
    signals:
      void dataChanged(AbstractCenterWidget* w, const QVariant& changed);
    
    protected:
      explicit AbstractCenterWidget(QWidget* parent = nullptr);
      virtual ~AbstractCenterWidget() = default;
    
      virtual QWidget* createContent();
    
    private:
      QAction*     vAction;
      QString      fileName;
      bool         addScrollArea;
      };
    

    ... and here one plugin declaration:

    #include <abscenterwidget.h>
    #include <PluginPageInterface.h>
    
    QT_BEGIN_NAMESPACE
    class FixtureEdit;
    class AxisMask;
    QT_END_NAMESPACE
    
    
    class FixtureManager : public AbstractCenterWidget
    {
      Q_OBJECT
      Q_PLUGIN_METADATA(IID "PluginPageInterface_iid" FILE "fixtureManager.json")
    public:
      FixtureManager(QWidget* parent = nullptr);
    
      virtual void connectSignals() override;
      virtual void updateStyles()   override;
      void activateEditor(int index);
    
    protected:
      virtual void keyPressEvent(QKeyEvent* event) override;
      virtual void showEvent(QShowEvent *event) override;
      virtual QWidget* createContent() override;
    
    private:
      QWidget*  client;
      QFont     cFonts[4];
      QString   cStyle[4];
      AxisMask* axisMask;
      };
    


  • I got it.

    Just as a dumb test I copied the plugin from plugandpaint sample into plugindir of my app and that got loaded.

    This showed me that the loader failures had nothing to do with my programming, but that there was a problem with the plugin files.

    So I investigated further in that direction and found out that no link errors are output at building the plugins. So if you think everything is error free, that is far from true for the plugins.

    Was then still a tough piece of work, but in the meantime all plugins get loaded.


Log in to reply