Hi, I'm writing a program that uses plugins to extend it. I followed the examples in QT. But when I run the application it gives the error: symbol lookup error: /home/cquiros/MyApplication/plugins/libtnkbasicplugins.so: undefined symbol: _ZN16tnkBasicPolygons13createPolygonE7QString.
From the error I can see that the problem is in the function createPolygon. This fuction is private for the plugin.
If I remove the private function createPolygon. The application works just fine.
Any idea what I am doing wrong?
Many thanks.
Here is the code:
tnkinterfaces.h
#ifndef TNKINTERFACES_H
#define TNKINTERFACES_H
#include <QtPlugin>
#include "tnkdelegatorfactory.h"
class tnkPolygonInterface
{
public:
virtual ~tnkPolygonInterface() {}
virtual QList<QIcon> pluginIcons() = 0;
virtual tnkPolygonSymbol
* constructNewItem
(const QString &pluginName,
bool inDesignMode
) = 0;
virtual tnkPolygonSymbol
* loadItemFromData
(const QString &pluginName,
QByteArray &data,
bool inDesignMode
) = 0;
};
Q_DECLARE_INTERFACE(tnkPolygonInterface,"com.personal.MyApplication.tnkPolygonInterface/1.0")
#endif // TNKINTERFACES_H
#ifndef TNKINTERFACES_H
#define TNKINTERFACES_H
#include <QtPlugin>
#include "tnkdelegatorfactory.h"
class QStringList;
class QIcon;
class tnkPolygonInterface
{
public:
virtual ~tnkPolygonInterface() {}
virtual QStringList pluginNames() const = 0;
virtual QList<QIcon> pluginIcons() = 0;
virtual tnkPolygonSymbol* constructNewItem(const QString &pluginName, bool inDesignMode) = 0;
virtual tnkPolygonSymbol* loadItemFromData(const QString &pluginName, QByteArray &data, bool inDesignMode) = 0;
};
Q_DECLARE_INTERFACE(tnkPolygonInterface,"com.personal.MyApplication.tnkPolygonInterface/1.0")
#endif // TNKINTERFACES_H
To copy to clipboard, switch view to plain text mode
tnkbasicplugins.h
#ifndef TNKBASICPLUGINS_H
#define TNKBASICPLUGINS_H
#include <QtGui>
#include <QObject>
#include <src/tnkinterfaces.h>
class tnkBasicPolygons
: public QObject,
public tnkPolygonInterface
{
Q_OBJECT
Q_INTERFACES(tnkPolygonInterface)
public:
QList<QIcon> pluginIcons();
tnkPolygonSymbol
* constructNewItem
(const QString &pluginName,
bool inDesignMode
);
tnkPolygonSymbol
* loadItemFromData
(const QString &pluginName,
QByteArray &data,
bool inDesignMode
);
private:
};
#endif // TNKBASICPLUGINS_H
#ifndef TNKBASICPLUGINS_H
#define TNKBASICPLUGINS_H
#include <QtGui>
#include <QObject>
#include <src/tnkinterfaces.h>
class tnkBasicPolygons : public QObject, public tnkPolygonInterface
{
Q_OBJECT
Q_INTERFACES(tnkPolygonInterface)
public:
QStringList pluginNames() const;
QList<QIcon> pluginIcons();
tnkPolygonSymbol* constructNewItem(const QString &pluginName, bool inDesignMode);
tnkPolygonSymbol* loadItemFromData(const QString &pluginName, QByteArray &data, bool inDesignMode);
private:
QPolygonF createPolygon(QString polygonType);
};
#endif // TNKBASICPLUGINS_H
To copy to clipboard, switch view to plain text mode
in the .h createPolygon(QString polygonType) is private and not declared in the interfaces.
tnkbasicplugins.cpp
#include "tnkbasicplugins.h"
{
}
QList<QIcon> tnkBasicPolygons::pluginIcons()
{
QList<QIcon> result;
// Create a 32x32 representation of the box
// and appends it to the list of icons
scene.
setSceneRect(QRectF(0,
0,
101,
101));
scene.addPolygon(createPolygon("Box"));
scene.render(&painter);
image.scaledToHeight(32);
image.scaledToWidth(32);
return result;
}
tnkPolygonSymbol
* tnkBasicPolygons
::constructNewItem(const QString &pluginName,
bool inDesignMode
){
tnkPolygonSymbol *result;
result = new tnkPolygonSymbol(0,0,inDesignMode); //Must change
if (pluginName == tr("Box"))
{
result->setPolygon(createPolygon("Box"));
//Need to see how to save data!
}
return result;
}
tnkPolygonSymbol
* tnkBasicPolygons
::loadItemFromData(const QString &pluginName,
QByteArray &data,
bool inDesignMode
){
tnkPolygonSymbol *result;
result = new tnkPolygonSymbol(0,0,inDesignMode); //Must change
if (pluginName == tr("Box"))
{
result->setPolygon(createPolygon("Box"));
//Need to see how to save data!
}
return result;
}
{
if (polygonType == "Box")
{
}
return sqPolygon;
}
Q_EXPORT_PLUGIN2(tnk_basicpolygons, tnkBasicPolygons)
#include "tnkbasicplugins.h"
QStringList tnkBasicPolygons::pluginNames() const
{
return QStringList() << tr("Box");
}
QList<QIcon> tnkBasicPolygons::pluginIcons()
{
QList<QIcon> result;
QImage image;
QPainter painter(&image);
// Create a 32x32 representation of the box
// and appends it to the list of icons
QGraphicsScene scene;
scene.setSceneRect(QRectF(0,0,101,101));
scene.addPolygon(createPolygon("Box"));
scene.render(&painter);
image.scaledToHeight(32);
image.scaledToWidth(32);
result.append(QIcon(QPixmap::fromImage(image)));
return result;
}
tnkPolygonSymbol* tnkBasicPolygons::constructNewItem(const QString &pluginName, bool inDesignMode)
{
tnkPolygonSymbol *result;
result = new tnkPolygonSymbol(0,0,inDesignMode); //Must change
if (pluginName == tr("Box"))
{
QPolygonF sqPolygon;
sqPolygon << QPointF(-100, -100) << QPointF(100, -100)
<< QPointF(100, 100) << QPointF(-100, 100)
<< QPointF(-100, -100);
result->setPolygon(createPolygon("Box"));
//Need to see how to save data!
}
return result;
}
tnkPolygonSymbol* tnkBasicPolygons::loadItemFromData(const QString &pluginName, QByteArray &data, bool inDesignMode)
{
tnkPolygonSymbol *result;
result = new tnkPolygonSymbol(0,0,inDesignMode); //Must change
if (pluginName == tr("Box"))
{
result->setPolygon(createPolygon("Box"));
//Need to see how to save data!
}
return result;
}
QPolygonF createPolygon(QString polygonType)
{
QPolygonF sqPolygon;
if (polygonType == "Box")
{
sqPolygon << QPointF(-100, -100) << QPointF(100, -100)
<< QPointF(100, 100) << QPointF(-100, 100)
<< QPointF(-100, -100);
}
return sqPolygon;
}
Q_EXPORT_PLUGIN2(tnk_basicpolygons, tnkBasicPolygons)
To copy to clipboard, switch view to plain text mode
Bookmarks