PDA

View Full Version : Nightmares with plugins



KShots
8th February 2007, 02:34
Hello all,

I'm having a considerable amount of trouble getting my plugins to work. Following the documentation (under the "How to Create Qt Plugins" section), I am following the low-level approach of creating plugins to extend my application through the use of QPluginLoader.

Currently, the whole mess compiles, but when I try to obtain an instance of my plugin, I get a NULL-pointer.

Here's what I've got:

The base plugin header:
#include <QObject>
#include <QList>
#include <QTcpSocket>
#include <QPluginLoader>

class QWorkspace;

/**
@author Richard F. Ostrow Jr. <kshots@warfaresdl.com>
*/
class formBasePlugin : public QObject
{
Q_OBJECT
public:
formBasePlugin(QObject * parent = 0);
virtual ~formBasePlugin();

int row();

virtual const QString pluginName()const = 0;
virtual void onActivate() = 0;

QList <formBasePlugin *> listChildren;
void unload(){emit removed();}
static QTcpSocket socketServer;
static QWorkspace * ws;
QPluginLoader * PL;
protected:
signals:
void removed();
public slots:
};

Q_DECLARE_INTERFACE(formBasePlugin, "evilrpg.warfaresdl/1.0")Then I've got the header for one of the plugins:
#include <formBasePlugin.h>

/**
@author Richard F. Ostrow Jr. <kshots@warfaresdl.com>
*/
class pluginWhiteboard : public formBasePlugin
{
Q_OBJECT
Q_INTERFACES(formBasePlugin)
public:
pluginWhiteboard(QObject * parent = 0);
virtual ~pluginWhiteboard();

virtual const QString pluginName()const{return tr("Whiteboard");}
virtual void onActivate();
};... and the implementation of said plugin:
Q_EXPORT_PLUGIN2(plugins, pluginWhiteboard)

pluginWhiteboard::pluginWhiteboard(QObject * parent) : formBasePlugin(parent)
{
setObjectName("pluginWhiteboard");
}

pluginWhiteboard::~pluginWhiteboard()
{
}

void
pluginWhiteboard::onActivate()
{
}My application successfully finds the plugin (I have checked this), but fails to load said plugin. Am I missing anything blatantly obvious? Thanks.

jacek
8th February 2007, 02:41
What is the name of a file that contains this plugin?

dcurtis
8th February 2007, 03:57
what system? windows or linux?

KShots
8th February 2007, 07:31
What is the name of a file that contains this plugin?

libplugins.so


what system? windows or linux?Both (in the end, at least). Currently testing with unix.

wysota
8th February 2007, 10:54
Do you have more than one plugin in the "libplugins" lib? I don't think this is possible... AFAIR you can have only one plugin export macro per plugin.

KShots
8th February 2007, 17:21
Do you have more than one plugin in the "libplugins" lib? I don't think this is possible... AFAIR you can have only one plugin export macro per plugin.I only have one "libplugins" plugin. This is my first shot at plugins (at least under Qt... I've used ld and libtool ld before), and I had a bit of a misunderstanding that I have not yet corrected. It will end up being libWhiteboard.

The name of the source file(s) are pluginWhiteboard.[h/cpp]

And also, because I forgot to post it, the contents of the .pro file for the plugin:
# Target is a library: whiteboard

QT = network core
INCLUDEPATH += ../src
TARGET = whiteboard
DESTDIR = ../bin/plugins
CONFIG += release \
warn_on \
qt \
plugin
TEMPLATE = lib
HEADERS += pluginWhiteboard.h
SOURCES += pluginWhiteboard.cpp

wysota
8th February 2007, 17:46
I think the name you put into the Q_EXPORT_PLUGIN2 macro is wrong.