[Qt-interest] Plugin framework

Tim Peeters thjmpeeters at gmail.com
Mon Nov 23 23:38:01 CET 2009


Hi,

I'm trying to write software that can be extended using plugins.
I follow the guidelines as given on
http://qt.nokia.com/doc/4.5/plugins-howto.html#the-lower-level-api-extending-qt-applications

I created a simple interface:

class TestInterface
{
  public:
    virtual ~TestInterface() {}
    virtual int testFunction() = 0;
};
Q_DECLARE_INTERFACE(TestInterface, "bmia.plugin.TestInterface/1.0")


and a plugin class:

class BogusPlugin : public QObject, public TestInterface
{
    Q_OBJECT
    Q_INTERFACES(TestInterface)

public:
    int testFunction();
}

and implementation:

int BogusPlugin::testFunction()
{
  return 2;
}
Q_EXPORT_PLUGIN2(BogusPlugin, BogusPlugin)


And I created a Manager class to manage my plugins. For now I have this
function to load a simple plugin:

bool Manager::load(string filename)
{
    cout<<"Going to try to load plugin from file "<<filename<<endl;

    QPluginLoader loader(QString(filename.c_str()));

    QFile* file = new QFile();
    file->setFileName(loader.fileName());
    cout<<"file exists = "<<file->exists()<<endl;
    delete file;

    if (!loader.load()) cout<<"bla"<<endl;

    QObject* loadedQObject = loader.instance();
    if (!loadedQObject)
    {
    cout<<"Plugin from file "<<filename<<" could not be loaded."<<endl; //
XXX: replace by core warning message, also below.
    return false;
    } // if
return true;
}

And I have a test program to see if I can load the BogusPlugin:

int main(int argv, char *args[])
{
   QApplication app(argv, args);
   plugin::Manager* m = new plugin::Manager();
   m->load("libbmia_BogusPlugin.so");
   return app.exec();
}

When I run the program, I get the following:

$ ./fakeplugin
Going to try to load plugin from file libbmia_BogusPlugin.so
file exists = 1
bla
Plugin from file libbmia_BogusPlugin.so could not be loaded.


All I know from this is that QPluginLoader.load(..) function returns false
and the plugin is not properly loaded.
But I cannot discover why this is happening. For building we use CMake. The
supposed plugin is compiled as a dll (bmia_BogusPlugin.so on linux), and the
main function is compiled for the fakeplugin executable that should load the
plugin. The file can be found, but no plugin is loaded from this.

Does anyone have an idea on what may be my problem? Maybe I am missing
something?

Thanks,
Tim.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20091123/11d3a670/attachment.html 


More information about the Qt-interest-old mailing list