Results 1 to 7 of 7

Thread: QPluginLoader doesn't load plugin

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    20
    Thanks
    2
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QPluginLoader doesn't load plugin

    Hello,

    i try to load a plugin into my application. I have followed the "Text Area" example from the book "C++ GUI Programming with Qt4" but my application refuses to load the plugin.

    That's how i have defined the plugin interface:

    Qt Code:
    1. #ifndef INTERFACE_H
    2. #define INTERFACE_H
    3.  
    4. #include <QtPlugin>
    5.  
    6. class PluginInterface
    7. {
    8. public:
    9. virtual ~PluginInterface() { }
    10.  
    11. virtual QString pluginName();
    12. };
    13.  
    14. Q_DECLARE_INTERFACE(PluginInterface, "cops.demo.PluginInterface/1.0")
    15.  
    16. #endif
    To copy to clipboard, switch view to plain text mode 

    Here is the code of the plugin:

    header-file:
    Qt Code:
    1. #ifndef MYPLUGIN_H
    2. #define MYPLUGIN_H
    3.  
    4. #include <QString>
    5.  
    6. #include "myPlugin.h"
    7. #include "../pluginInterface.h"
    8.  
    9.  
    10. class MyPlugin : public QObject, public PluginInterface
    11. {
    12.  
    13. Q_OBJECT
    14. Q_INTERFACES(PluginInterface)
    15.  
    16. public:
    17. QString pluginName();
    18.  
    19. };
    20.  
    21. #endif
    To copy to clipboard, switch view to plain text mode 

    and source file:
    Qt Code:
    1. #include <QtGui>
    2. #include <iostream>
    3.  
    4. #include "myPlugin.h"
    5.  
    6. QString MyPlugin::pluginName()
    7. {
    8. return "My Plugin Name";
    9. }
    10.  
    11. Q_EXPORT_PLUGIN2(myplugin, MyPlugin)
    To copy to clipboard, switch view to plain text mode 

    I can compile the plugin and get a libmyPlugin.so in my plugin directory.

    Here you can see how i try to load the plugin in my application:

    Qt Code:
    1. void MainWindow::loadPlugins()
    2. {
    3. QDir pluginDir(QApplication::applicationDirPath());
    4.  
    5. if (!pluginDir.cd("plugins"))
    6. return;
    7.  
    8. foreach (QString fileName, pluginDir.entryList(QDir::Files)) {
    9. std::cout << qPrintable(fileName) << "\n";
    10. QPluginLoader loader(pluginDir.absoluteFilePath(fileName));
    11. if (PluginInterface *interface = qobject_cast<PluginInterface *>(loader.instance())) {
    12. interfaces.append(interface);
    13. std::cout << qPrintable(interface->pluginName()) << "loaded \n";
    14. } else {
    15. std::cout << "not loaded!\n";
    16. }
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    The program finds the plugin ("std::cout << qPrintable(fileName) << "\n";" shows the filename of the plugin) but the if statement is always false so that i end in the else-arm.

    Do you have an idea what's wrong here?

    Thanks a lot!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPluginLoader doesn't load plugin

    What does QPluginLoader::isLoaded() return? What does QPluginLoader::errorString() return?

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    20
    Thanks
    2
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader doesn't load plugin

    QPluginLoader::isLoaded() returns false and QPluginLoader::errorString() says:

    QLibrary::load_sys: Cannot load /home/foo/src/demo/plugins/libmyPlugin.so (/home/foo/src/demo/plugins/libmyPlugin.so: undefined symbol: _ZTI15PluginInterface)

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPluginLoader doesn't load plugin

    The method in the interface should be pure virtual (=0) so that you don't have to have a constructor.

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

    Default Re: QPluginLoader doesn't load plugin

    That symbol has something to do with RTTI. Did you compile the plugin with the same options as Qt? Also add = 0 after pluginName() in PluginInterface.

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    20
    Thanks
    2
    Thanked 4 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPluginLoader doesn't load plugin

    Thank you! The missing "= 0" was the problem, now it works.

    Maybe a dump question but why do i need "= 0" at the end of the method?

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

    Default Re: QPluginLoader doesn't load plugin

    Quote Originally Posted by BeS View Post
    Maybe a dump question but why do i need "= 0" at the end of the method?
    "= 0" means that the method is abstract. I.e. it has no implementation in this class and that this implementation will be provided by derived classes.

    Without = 0, if you won't provide some implementation of that method, you will get linker error when you try to use it.

Similar Threads

  1. Designer doesn't load wwWidgets plugin
    By reimer in forum Installation and Deployment
    Replies: 21
    Last Post: 7th February 2009, 03:23
  2. Plugin implementation question
    By JPNaude in forum Qt Programming
    Replies: 12
    Last Post: 27th August 2008, 20:24
  3. custom plugin load fails...
    By raman_31181 in forum Qt Tools
    Replies: 3
    Last Post: 3rd July 2008, 09:37
  4. Load form mdi child plugin
    By estanisgeyer in forum Qt Programming
    Replies: 4
    Last Post: 10th February 2008, 14:27
  5. QPluginLoader not recognizing a plugin
    By KShots in forum Qt Programming
    Replies: 3
    Last Post: 29th June 2007, 14:13

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.