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
Qt Code:
  1. #ifndef TNKINTERFACES_H
  2. #define TNKINTERFACES_H
  3.  
  4. #include <QtPlugin>
  5. #include "tnkdelegatorfactory.h"
  6.  
  7. class QIcon;
  8.  
  9. class tnkPolygonInterface
  10. {
  11. public:
  12. virtual ~tnkPolygonInterface() {}
  13. virtual QStringList pluginNames() const = 0;
  14. virtual QList<QIcon> pluginIcons() = 0;
  15. virtual tnkPolygonSymbol* constructNewItem(const QString &pluginName, bool inDesignMode) = 0;
  16. virtual tnkPolygonSymbol* loadItemFromData(const QString &pluginName, QByteArray &data, bool inDesignMode) = 0;
  17. };
  18.  
  19. Q_DECLARE_INTERFACE(tnkPolygonInterface,"com.personal.MyApplication.tnkPolygonInterface/1.0")
  20.  
  21. #endif // TNKINTERFACES_H
To copy to clipboard, switch view to plain text mode 

tnkbasicplugins.h
Qt Code:
  1. #ifndef TNKBASICPLUGINS_H
  2. #define TNKBASICPLUGINS_H
  3.  
  4. #include <QtGui>
  5. #include <QObject>
  6. #include <src/tnkinterfaces.h>
  7.  
  8. class tnkBasicPolygons : public QObject, public tnkPolygonInterface
  9. {
  10. Q_OBJECT
  11. Q_INTERFACES(tnkPolygonInterface)
  12. public:
  13. QStringList pluginNames() const;
  14. QList<QIcon> pluginIcons();
  15. tnkPolygonSymbol* constructNewItem(const QString &pluginName, bool inDesignMode);
  16. tnkPolygonSymbol* loadItemFromData(const QString &pluginName, QByteArray &data, bool inDesignMode);
  17. private:
  18. QPolygonF createPolygon(QString polygonType);
  19. };
  20.  
  21. #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
Qt Code:
  1. #include "tnkbasicplugins.h"
  2.  
  3.  
  4. QStringList tnkBasicPolygons::pluginNames() const
  5. {
  6. return QStringList() << tr("Box");
  7. }
  8.  
  9.  
  10. QList<QIcon> tnkBasicPolygons::pluginIcons()
  11. {
  12. QList<QIcon> result;
  13. QImage image;
  14. QPainter painter(&image);
  15.  
  16. // Create a 32x32 representation of the box
  17. // and appends it to the list of icons
  18. scene.setSceneRect(QRectF(0,0,101,101));
  19. scene.addPolygon(createPolygon("Box"));
  20. scene.render(&painter);
  21. image.scaledToHeight(32);
  22. image.scaledToWidth(32);
  23. result.append(QIcon(QPixmap::fromImage(image)));
  24.  
  25.  
  26. return result;
  27. }
  28.  
  29. tnkPolygonSymbol* tnkBasicPolygons::constructNewItem(const QString &pluginName, bool inDesignMode)
  30. {
  31. tnkPolygonSymbol *result;
  32. result = new tnkPolygonSymbol(0,0,inDesignMode); //Must change
  33. if (pluginName == tr("Box"))
  34. {
  35. QPolygonF sqPolygon;
  36. sqPolygon << QPointF(-100, -100) << QPointF(100, -100)
  37. << QPointF(100, 100) << QPointF(-100, 100)
  38. << QPointF(-100, -100);
  39. result->setPolygon(createPolygon("Box"));
  40.  
  41. //Need to see how to save data!
  42.  
  43. }
  44. return result;
  45. }
  46.  
  47. tnkPolygonSymbol* tnkBasicPolygons::loadItemFromData(const QString &pluginName, QByteArray &data, bool inDesignMode)
  48. {
  49. tnkPolygonSymbol *result;
  50. result = new tnkPolygonSymbol(0,0,inDesignMode); //Must change
  51. if (pluginName == tr("Box"))
  52. {
  53.  
  54. result->setPolygon(createPolygon("Box"));
  55.  
  56. //Need to see how to save data!
  57.  
  58. }
  59. return result;
  60. }
  61.  
  62.  
  63. QPolygonF createPolygon(QString polygonType)
  64. {
  65. QPolygonF sqPolygon;
  66. if (polygonType == "Box")
  67. {
  68. sqPolygon << QPointF(-100, -100) << QPointF(100, -100)
  69. << QPointF(100, 100) << QPointF(-100, 100)
  70. << QPointF(-100, -100);
  71. }
  72. return sqPolygon;
  73. }
  74.  
  75. Q_EXPORT_PLUGIN2(tnk_basicpolygons, tnkBasicPolygons)
To copy to clipboard, switch view to plain text mode