Results 1 to 7 of 7

Thread: plugin loading problem

  1. #1
    Join Date
    Feb 2006
    Location
    Warsaw, Poland
    Posts
    45
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default plugin loading problem

    Hi there! I'm trying to play with plugins for my app...

    here is some code:

    plugin interface:
    Qt Code:
    1. #ifndef PLUGINIF_H
    2. #define PLUGINIF_H
    3.  
    4. class PluginInterface {
    5. public:
    6. virtual ~PluginInterface() {}
    7. virtual QString version();
    8. virtual QString author();
    9. virtual QString description();
    10. virtual QString name();
    11. };
    12.  
    13. Q_DECLARE_INTERFACE(PluginInterface, "Qxygen.PluginInterface")
    14.  
    15. #endif
    To copy to clipboard, switch view to plain text mode 

    plugin header:
    Qt Code:
    1. #ifndef PLUGIN_H
    2. #define PLUGIN_H
    3.  
    4. #include <QObject>
    5. #include <pluginif.h>
    6.  
    7. class plugin: public QObject, public PluginInterface {
    8. Q_OBJECT
    9. Q_INTERFACES(PluginInterface)
    10.  
    11. public:
    12. QString author();
    13. QString version();
    14. QString description();
    15. QString name();
    16. };
    17.  
    18. #endif
    To copy to clipboard, switch view to plain text mode 

    plugin implementation:
    Qt Code:
    1. #include <QtPlugin>
    2.  
    3. #include "plugin.h"
    4.  
    5. QString plugin::author() {
    6. return "Naresh";
    7. }
    8.  
    9. QString plugin::version() {
    10. return "0.0.1";
    11. }
    12.  
    13. QString plugin::description() {
    14. return "plugin descr";
    15. }
    16.  
    17. QString plugin::name() {
    18. return "plugin";
    19. }
    20.  
    21. Q_EXPORT_PLUGIN2(my_plugin, plugin)
    To copy to clipboard, switch view to plain text mode 

    here is plugin loading loop:

    Qt Code:
    1. QDir dir( QCoreApplication::applicationDirPath()+"/plugins/" );
    2. QStringList fileNames=dir.entryList( QStringList("*.so"), QDir::Files, QDir::Name);
    3.  
    4. foreach( QString fileName, fileNames ) {
    5. qDebug()<<dir.absoluteFilePath(fileName); // returns proper path everytime
    6. QPluginLoader loader( dir.absoluteFilePath(fileName) );
    7. QObject *plugin=loader.instance();
    8. if ( plugin ) {
    9. PluginInterface *plif=qobject_cast<PluginInterface*>( plugin );
    10. QStringList values;
    11. values<< plif->name() << plif->version();
    12. new QTreeWidgetItem( ui.pluginList, values );
    13. }
    14. qDebug()<<loader.isLoaded(); // always return false
    15. }
    To copy to clipboard, switch view to plain text mode 

    project file looks like this:
    Qt Code:
    1. TEMPLATE = lib
    2. CONFIG += plugin release
    3. INCLUDEPATH += ../interfaces
    4. TARGET = ../../plugins/plugin
    5. VERSION=0.0.1
    6.  
    7. HEADERS = \
    8. plugin.h
    9.  
    10. SOURCES = \
    11. plugin.cpp
    To copy to clipboard, switch view to plain text mode 

    As you can see in comments... plugin loading loop always return false for isLoaded and never loads plugin... and path it uses always is proper... any ideas?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: plugin loading problem

    Quote Originally Posted by naresh
    Q_EXPORT_PLUGIN2(my_plugin, plugin)
    TARGET = ../../plugins/plugin
    These names must match.

  3. #3
    Join Date
    Feb 2006
    Location
    Warsaw, Poland
    Posts
    45
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: plugin loading problem

    I've changed those lines to be same but still can't load it...

  4. #4
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: plugin loading problem

    The Qt plugin classes are really hard to use. Usually you have no idea why loading fails. I noticed that plugins are extremely sensitive to bugs in the .pro files.

    If even one of your .h or .cpp files includes a .h which is not in your .pro file, even if not used at all, plugin loading might fail.

    I usually even create a fake .cpp file for each interface file to put it in the .pro file.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: plugin loading problem

    Quote Originally Posted by Kumosan
    The Qt plugin classes are really hard to use. Usually you have no idea why loading fails.
    Never tried it, but "static plugins" might produce linker errors.

    Anyway the problem with the above plugin was that the interface wasn't a real interface.
    It should be:
    Qt Code:
    1. public:
    2. virtual QString author() = 0;
    3. virtual QString version() = 0;
    4. virtual QString description() = 0;
    5. virtual QString name() = 0;
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    May 2007
    Location
    Netherlands
    Posts
    11
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: plugin loading problem

    Hi,

    I am busy trying to figure out what goes wrong. I developed some plugins for the qt designer and sometimes it did not load either. To test if a plugin will load, you can do the following:

    create a file called main.cpp with just this:

    int main(int argc, char* argv[])
    {
    return 0;
    }

    then compile (libfirstplugin.so is the plugin you like to test)

    g++ test.cpp libfirstplugin.so

    In case of your code, I got:

    libfirstplugin.so: undefined reference to `typeinfo for PluginInterface'
    libfirstplugin.so: undefined reference to `vtable for PluginInterface'

    So this is I guess why the plugin is not loading. I am searching for an answer on these messages

  7. #7
    Join Date
    May 2007
    Location
    Netherlands
    Posts
    11
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: plugin loading problem

    Hi,

    See attachment, it works now. Maybe you can check if it also works for your application.

    Cheers,

    Jeroen
    Attached Files Attached Files

  8. The following user says thank you to Jeroen van der Waal for this useful post:

    nsa777 (18th July 2007)

Similar Threads

  1. Dynamic lookup problem
    By jwintz in forum Qt Programming
    Replies: 3
    Last Post: 30th May 2006, 15:19
  2. creating table plugin
    By mgurbuz in forum Qt Programming
    Replies: 3
    Last Post: 28th April 2006, 14:50
  3. general sqlplugin problem
    By a550ee in forum Installation and Deployment
    Replies: 5
    Last Post: 28th February 2006, 11:03
  4. Runtime dynamic linking + Qt4 problem
    By _Ramirez_ in forum Qt Programming
    Replies: 5
    Last Post: 11th February 2006, 15:28
  5. Replies: 7
    Last Post: 3rd February 2006, 11:20

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.