Results 1 to 4 of 4

Thread: QPluginLoader not recognizing a plugin

  1. #1
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default QPluginLoader not recognizing a plugin

    Hello all...

    I've been staring at this for over an hour and I've got to admit... I'm about out of ideas.

    I have a plugin (using the low-level approach) that QPluginLoader returns a NULL pointer on when instance() is called. This tends to tell me that (a) The plugin is not being built as a plugin, (b) Qt is not recognizing some name somewhere, or (c) I'm just losing my mind.

    I have several other *kinds* of plugins, all of which work perfectly. This is the only plugin of its kind, so it's possible that the plugin interface is borked.

    Anyways, each plugin inherits from a master plugin interface (combines common functionality into a single class which all other plugins inherit from):
    Qt Code:
    1. class evilcpcPlugin
    2. {
    3. public:
    4. virtual ~evilcpcPlugin(){}
    5.  
    6. /** Returns a short, descriptive name for this plugin*/
    7. virtual const QString getName()const = 0;
    8. /** Returns a longer description for this plugin*/
    9. virtual const QString getDescription()const = 0;
    10. /** Returns the name of the author of this plugin*/
    11. virtual const QString getAuthor()const = 0;
    12. /** Checks whether or not this plugin has encountered an error*/
    13. virtual const bool isValid()const = 0;
    14. /** Returns the nature of an error if this plugin is marked as invalid*/
    15. virtual const QString errorString()const = 0;
    16. /** This will return an instance of the configuration dialog for this
    17.   * plugin. Return a 0 if you need no configuration*/
    18. virtual evilcpcPluginWidgetConfig * getConfigWidget(QWidget * parent) = 0;
    19. /** This will return an instance of the carPC-side daemon utilized for
    20.   * remote configuration of this plugin. Return a 0 if your plugin needs
    21.   * no configuration*/
    22. virtual evilcpcPluginWidgetConfigDaemon * getConfigWidgetDaemon(QWidget * parent) = 0;
    23. };
    To copy to clipboard, switch view to plain text mode 
    This base class works fine with other plugin types. The actual interface class is this:
    Qt Code:
    1. # include <QtPlugin>
    2. # include <evilcpcPlugin.h>
    3.  
    4. class QWidget;
    5. class evilcpcMixerWidget;
    6.  
    7. /** This interface fills the purpose of describing and creating a given mixer
    8.  * plugin */
    9. class evilcpcMixer : public evilcpcPlugin
    10. {
    11. public:
    12. virtual ~evilcpcMixer(){}
    13.  
    14. /** Creates an widget for the mixer plugin to use. This widget will
    15.   * handle control of all audio mixer properties. This will stay
    16.   * resident at all times.
    17.   * @parent - This will be a pointer to the menu plugin's widget*/
    18. virtual evilcpcMixerWidget * getWidget(QWidget * parent) = 0;
    19. };
    20.  
    21. Q_DECLARE_INTERFACE(evilcpcMixer,
    22. "com.warfaresdl.evilcpc.evilcpcMixer/1.0.0")
    To copy to clipboard, switch view to plain text mode 
    Pretty simple stuff... I can't imagine there's anything screwy here. Then there's the plugin class, which fills in all the pure virtuals:
    Qt Code:
    1. # include <evilcpcMixer.h>
    2. # include <QObject>
    3.  
    4. class evilcpcMixerOSS : public QObject, public evilcpcMixer
    5. {
    6. Q_OBJECT
    7. Q_INTERFACES(evilcpcMixer)
    8. public:
    9. evilcpcMixerOSS(QObject * parent = 0);
    10. virtual ~evilcpcMixerOSS();
    11.  
    12. virtual const QString getName()const{return tr("OSSv3 mixer");}
    13. virtual const QString getDescription()const{return tr("Mixer plugin utilizing the OSS v3 library");}
    14. virtual const QString getAuthor()const{return "Richard F. Ostrow Jr.";}
    15. virtual const bool isValid()const{return valid;}
    16. virtual const QString errorString()const{return error;}
    17. virtual evilcpcMixerWidget * getWidget(QWidget * parent);
    18. virtual evilcpcPluginWidgetConfig * getConfigWidget(QWidget * parent);
    19. virtual evilcpcPluginWidgetConfigDaemon * getConfigWidgetDaemon(QWidget * parent);
    20. protected:
    21. QString error;
    22. bool valid;
    23. evilcpcMixerWidget * w;
    24. evilcpcPluginWidgetConfig * cw;
    25. evilcpcPluginWidgetConfigDaemon * cwd;
    26. };
    To copy to clipboard, switch view to plain text mode 
    Again, pretty simple. And the implementation also contains the Q_EXPORT_PLUGIN2 line, as follows:
    Qt Code:
    1. Q_EXPORT_PLUGIN2(LIBTARGET, evilcpcMixerOSS)
    To copy to clipboard, switch view to plain text mode 
    LIBTARGET is defined in the end of the project file:
    Qt Code:
    1. TEMPLATE = lib
    2. HEADERS += evilcpcMixerOSS.h \
    3. evilcpcMixerOSSWidget.h \
    4. evilcpcMixerOSSWidgetConfig.h \
    5. evilcpcMixerOSSWidgetConfigDaemon.h \
    6. ../interface/evilcpcMixer.h \
    7. ../interface/evilcpcMixerWidget.h \
    8. ../../interface/evilcpcPluginWidgetConfig.h \
    9. ../../interface/evilcpcPluginWidgetConfigDaemon.h \
    10. ../../interface/evilcpcPlugin.h
    11. SOURCES += evilcpcMixerOSS.cpp \
    12. evilcpcMixerOSSWidget.cpp \
    13. evilcpcMixerOSSWidgetConfig.cpp \
    14. evilcpcMixerOSSWidgetConfigDaemon.cpp
    15. FORMS += formOSSMixer.ui \
    16. formOSSMixerConfig.ui
    17. RESOURCES += ossmixer.qrc
    18. VERSION = 1.0.0
    19. CONFIG += plugin debug_and_release qt resources
    20. QT += core gui
    21. INCLUDEPATH = ../interface ../../interface
    22.  
    23. CONFIG(debug, debug|release) {
    24. TARGET = evilcpcMixerOSS_debug
    25. DEFINES += LIBTARGET=evilcpcMixerOSS_debug
    26. } else {
    27. TARGET = evilcpcMixerOSS
    28. DEFINES += LIBTARGET=evilcpcMixerOSS
    29. }
    To copy to clipboard, switch view to plain text mode 
    I went to the trouble of making sure that each interface was included in the HEADERS line of the project file, used the lib template, and added plugin to the CONFIG line. What could I possibly be missing?
    Life without passion is death in disguise

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader not recognizing a plugin

    Quote Originally Posted by KShots View Post
    What could I possibly be missing?
    So many things... :P But let's start with the most obvious one : unresolved symbols... When you build a shared library (and plugins are shared libraries) you must export some symbols... The thing, which already happened to me, is that when a method is declared but NOT defined within the plugin it can result in a "symbol lookup error" when QPluginLoader (through QLibrary actually) tries to load the plugin. This prevent the plugin instance to be created... To make sure this is not happening (or when it happens to locate the troublesome function) all you need is to create a simple test app with just a empty main() function and which LINKS to the plugin (it does not load it on run-time!!! it LINKS so you got to add the plugin to LIBS variable). This way all missing symbols should be notified when linking the test app and you'll see what to fix
    Current Qt projects : QCodeEdit, RotiDeCode

  3. The following user says thank you to fullmetalcoder for this useful post:

    KShots (28th June 2007)

  4. #3
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QPluginLoader not recognizing a plugin

    Quote Originally Posted by fullmetalcoder View Post
    So many things... :P But let's start with the most obvious one : unresolved symbols... When you build a shared library (and plugins are shared libraries) you must export some symbols... The thing, which already happened to me, is that when a method is declared but NOT defined within the plugin it can result in a "symbol lookup error" when QPluginLoader (through QLibrary actually) tries to load the plugin. This prevent the plugin instance to be created... To make sure this is not happening (or when it happens to locate the troublesome function) all you need is to create a simple test app with just a empty main() function and which LINKS to the plugin (it does not load it on run-time!!! it LINKS so you got to add the plugin to LIBS variable). This way all missing symbols should be notified when linking the test app and you'll see what to fix
    Wow... you were right. The problems (there were a few missing symbols) were not anywhere in those sections, but in an entirely different area... and I would never have seen it without making that simple app. Thanks!

    Heh, that's the way I really prefer to get answers - teach me to fish rather than give me a fish - now I can handle this sort of problem at any time. That's incredibly valuable .
    Life without passion is death in disguise

  5. #4
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPluginLoader not recognizing a plugin

    Quote Originally Posted by KShots View Post
    Wow... you were right. The problems (there were a few missing symbols) were not anywhere in those sections, but in an entirely different area... and I would never have seen it without making that simple app. Thanks!
    I've been playing with plugins since about a year now and it took me a while to think about this trick so I thought it would be worth sharing it Good to see that it helped you.

    Quote Originally Posted by KShots View Post
    Heh, that's the way I really prefer to get answers - teach me to fish rather than give me a fish - now I can handle this sort of problem at any time. That's incredibly valuable .
    That's the point of a forum : sharing knowledge after having experienced several aspects of programming. We look like old soldiers sharing little tricks on how to survive on a battlefield
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. plugin loading problem
    By naresh in forum Qt Programming
    Replies: 6
    Last Post: 9th June 2007, 20:05
  2. Qt4 win opensource + mysql plugin
    By vr in forum Installation and Deployment
    Replies: 3
    Last Post: 25th May 2007, 10:01
  3. QPluginLoader Qt 4
    By rianquinn in forum Qt Programming
    Replies: 9
    Last Post: 2nd October 2006, 08:04

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.