Results 1 to 8 of 8

Thread: Plugin and shared class between plugin and application

  1. #1
    Join Date
    Aug 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Plugin and shared class between plugin and application

    Hi !
    Well, I need to create a plugin manager, and some plugins to my application.
    The goal of a plugin is to provide new items to the main application, extended from QGraphicsWidget with a few more methods and signals.
    Since a plugin must be a pure interface, I realized one with some functions to communicate with the application.
    Since the item is used by the application, but also need to be know by the plugin to create them, I include in the header of the plugin the declaration of the Item (it's a QGraphicsWidget with some pure virtual methods)

    I manage to get my program and my plugin to compile. However, when I load the plugin, I get this error (came from pluginLoader.errorString() ) :

    PluginManager : instance failed "Cannot load library /home/wishper/trunk/release/Plugins/lib_basicitems.so: (/home/wishper/trunk/release/Plugins/lib_basicitems.so: undefined symbol: _ZN4Item16staticMetaObjectE)"

    Here is the light version of the header :
    Qt Code:
    1. class Item : public QGraphicsWidget{
    2. Q_OBJECT
    3. public:
    4. Item(QGraphicsItem * parent) : QGraphicsWidget(parent){};
    5. ~Item(){};
    6. virtual bool isBackground() = 0;
    7. virtual QList<PropertyInfo> getProperties() = 0;
    8.  
    9. signals:
    10. void background(bool background);
    11. void propertyUpdate();
    12. };
    13.  
    14. class ItemCreator{
    15. public:
    16. ~ItemCreator(){};
    17. virtual Item * createItem(QByteArray init);
    18. };
    19.  
    20. class Plugin
    21. {
    22. public:
    23. virtual ~Plugin() {};
    24. virtual QString getName() = 0;
    25. virtual QList<QMenu * > getMenus() = 0;
    26. virtual ItemCreator getItemCreator() = 0;
    27. virtual QList<QByteArray *> getInitValues() = 0;
    28. };
    29.  
    30. Q_DECLARE_INTERFACE(Plugin,
    31. "fr.neticoa.xsimulbeta.plugin/1.0")
    To copy to clipboard, switch view to plain text mode 

    What I see with the error is that the problem came from the Item class. I really don't understand what is the problem. I tried many things, but the result is always the same.

    Am I doing things wrong ?

    Thanks a lot, regards.
    wishper.
    Last edited by wishper; 18th August 2010 at 16:25.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Plugin and shared class between plugin and application

    Some obvious things to check:
    1. Are all functions implemented?
    2. Are the class definitions the same between the plugin and the program? (basically the first question again)
    3. Can all libraries be found (I don't think that's the problem here)

    By the way, did you check out the plugin examples in the documentation?

  3. #3
    Join Date
    Aug 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Plugin and shared class between plugin and application

    Well, I looked one more time. So yes, all my functions are implemented. The plugin and the application use the same header file, so it a yes for the second question.
    And, yes too for the libraries.

    But, there is hope ! After many tests, I succeed to load my plugin !
    Apparently, the problem came from the Item definition. First, I need to declare it as an interface, and next I must remove the Q_OBJECT macro.
    However, I can still extend the Item class from QGraphicsWidget, so the only drawback is for the signal (no macro, no signal ...), but I can use another interface to replace this, so it's not very bad.

    I will let you know when my plugin will really work : I need to change some things in my program to be able to test the creation of items.

  4. #4
    Join Date
    Aug 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Plugin and shared class between plugin and application

    Finally it works !
    So, the problem came from the Q_OBJECT macro, but it's seems that the fact that an interface is extended from a Qt class do not make problem.

    For the signal, I found a solution, but it's a little .. dirty ?
    In fact, since a signal is just a protected method, you can declare them in the interface, like a protected pure virtual method.
    And in the class which implement the interface, you declare them as signal. (In fact, you don't ever need to declare them in the interface, but not do it seems far too dirty for me )
    I can't decide if this method is a good one or not, it works ... but it's really sound like a trick.

    Regards.

  5. #5
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: Plugin and shared class between plugin and application

    Hi

    I don't really know if it will work for your plugin design (with your class being an interface), but I already extended a QGraphicsItem so it has signals/slots too, this way :

    Qt Code:
    1. #ifndef _TSP_HANDLE_H_
    2. #define _TSP_HANDLE_H_
    3.  
    4. #include <QObject>
    5. #include <QGraphicsItem>
    6.  
    7.  
    8. class Handle : public QObject, public QGraphicsItem
    9. {
    10. Q_OBJECT
    11.  
    12. Q_INTERFACES(QGraphicsItem)
    13.  
    14. public :
    15. enum {Type = QGraphicsItem::UserType + 7};
    16. virtual int type(void) const { return Handle::Type; }
    17.  
    18. public :
    19. Handle(TSPScene *scene,int id,int state) ;
    20.  
    21. virtual QPainterPath shape(void) const ;
    22. virtual QRectF boundingRect(void) const ;
    23. virtual void paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *) ;
    24.  
    25. signals :
    26. void activated(int id,int s) ;
    27. void deactivated(int id) ;
    28. void updated(int id,const QPointF &cursorPos) ;
    29. } ;
    30.  
    31. #endif // _TSP_HANDLE_H_
    To copy to clipboard, switch view to plain text mode 

    this code has been compiled, linked and executed successfully on windows.
    If you want to try, let me know if it worked

  6. #6
    Join Date
    Aug 2010
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Plugin and shared class between plugin and application

    Well, I fear that this way won't work. In fact, you can't use the Q_OBJECT macro in the interface, since you must have only pure virtual method. And, with no Q_OBJECT macro, it became pretty hard to obtain signal.
    In fact, before using plugin, I had declare my object almost like that : extending of a QGraphicsObject.

    By the way, I was wondering what is the interest of your design ? What I mean is that there is the QGraphicsObject (fusion of a QGraphicsItem and a QObject) which provide a QGraphicsItem with slot and signals capabilities, why use your classes instead of this ?
    I'm sure there is one, but I really don't see where

    Regards.

  7. #7
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: Plugin and shared class between plugin and application

    Well yeah, I was afraid I missed something, but QGraphicsObject doc says :

    Qt Code:
    1. This class was introduced in Qt 4.6.
    To copy to clipboard, switch view to plain text mode 

    And I'm still in 4.5.3 (waiting for 4.7) so here is the reason

    Sorry for my previous answer, I should have read more carefully
    Good luck !

  8. #8
    Join Date
    Dec 2007
    Posts
    27
    Thanks
    1
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Plugin and shared class between plugin and application

    Isn't the symbol "_ZN4Item16staticMetaObjectE" generated by the meta object compiler (moc)?
    Did you forget to link the generated moc_*.cpp file into your plugin? That would explain why the remove of Q_OBJECT would lead to success. Q_OBJECT requires the Implementations from the moc_x.cpp file.

Similar Threads

  1. Replies: 7
    Last Post: 11th April 2013, 11:55
  2. Qt Creator Custom widget plugin being replaced with parent class
    By mhill in forum Qt Tools
    Replies: 0
    Last Post: 28th July 2010, 19:58
  3. Class name mismatch for plugin
    By martinb0820 in forum Qt Tools
    Replies: 3
    Last Post: 20th August 2008, 14:47
  4. What about a plugin application?
    By Raccoon29 in forum Newbie
    Replies: 4
    Last Post: 16th March 2008, 17:36
  5. [SOLVED] Q_ENUMS from another class inside a plugin
    By desch in forum Qt Programming
    Replies: 1
    Last Post: 1st December 2007, 16:44

Tags for this Thread

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.