Results 1 to 5 of 5

Thread: Dynamic load QT Plugin - symbol lookup error

  1. #1
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Question Dynamic load QT Plugin - symbol lookup error

    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 

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Dynamic load QT Plugin - symbol lookup error

    What happens if you make createPolygon() protected rather than private?

  3. #3
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic load QT Plugin - symbol lookup error

    The same error happens whether is private, protected or public.

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Dynamic load QT Plugin - symbol lookup error

    It sounds like the loader can't find your plugin. Are you checking results to see if it located it, loaded it and cast it to the correct type?

  5. #5
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Dynamic load QT Plugin - symbol lookup error

    oh Man!!!! After maybe 8 hours in this crazy bug I just realized that I declared in the cpp:

    QPolygonF createPolygon(QString polygonType) and not QPolygonF tnkBasicPolygons::createPolygon(QString polygonType)

    And that was the error!..

    Many thanks for the replies!

Similar Threads

  1. Load objects from dynamic library
    By Trok in forum Qt Programming
    Replies: 10
    Last Post: 17th July 2009, 20:04
  2. QT-Embedded Symbol Lookup Error
    By augusbas in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 23rd June 2009, 05:01
  3. symbol lookup error when using plugins
    By macbeth in forum Qt Programming
    Replies: 3
    Last Post: 29th July 2006, 09:54
  4. Dynamic lookup problem
    By jwintz in forum Qt Programming
    Replies: 3
    Last Post: 30th May 2006, 14:19
  5. Replies: 3
    Last Post: 27th February 2006, 05:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.