PDA

View Full Version : signals and slots in plugins



anderl
10th October 2007, 13:37
Hi,

i'm trying to use signals and slots in plugins that will be loaded at runtime. But the plugins fails to load and i get this message:

"QLibrary::load_sys: Cannot load libvectorplugin.so.1.0.0 (libvectorplugin.so.1.0.0: undefined symbol: _ZN10App4Calcs11ICalculator10metaObjectEv)"

The plugin contains implementations of the following interfaces:


class ICalculator : public QObject
{
Q_OBJECT
public:
IView * createView() = 0;
(...)
signals:
void calculationDone();
};




class IView : public QObject
{
Q_OBJECT
public:
(..)
public slots:
virtual void renderData() =0;
};


and finally the plugin interface (the implementation of this inteface will be exported as a plugin):



class IPlugin
{
public:
ICalculator* createCalculator() = 0;
};
Q_DECLARE_INTERFACE(App::Calcs::IPlugin ,"IPlugin");


Implementation inside the plugin:

class VectorView : public IView
{
Q_OBJECT
public slots:
virtual void renderData()
{
(..)
}
};


class VectorCalculator : ICalculator
{
Q_OBJECT
public:
virtual void calculate()
{
(...)
emit calculationDone();
}
};

the qmake file:

TEMPLATE = lib
CONFIG += warn_on \
thread \
qt
TARGET = ../bin/vectorcalculator

QT += gui opengl
HEADERS += vectorcalculator.h
vectorview.h \
vectorplugin.h

SOURCES += vectorcalculator.cpp vectorview.cpp vectorplugin.cpp
The compilation works fine. Why do i get this linker error at runtime?

thanks in advance!

wysota
10th October 2007, 13:57
Interfaces can't be QObjects. The interface should contain virtual methods that will be implemented by each plugin. Only the plugin itself should inherit QObject and you can define signals and slots there. Then you can ask the plugin for available signals and slots using the meta object.