[Qt-interest] I don't get the plugin systems documentation

niklas berglund niklas.berglund at gmail.com
Tue Feb 24 23:46:19 CET 2009


Plugin loads... But I cannot use the plugin instance.I'm getting bus error.

Basically I create a QPluginLoader object for a plugin, run instance() to
get a QObject and then typecast the instance to my interface class, then run
a member function but thats when I get bus error.
Code uploaded to http://pastebin.com/f808bd4b but also pasted here:


#include <QtCore/QCoreApplication>

#include <QPluginLoader>

#include <QDebug>

#include <QLibrary>

#include "/Users/niklas/code/test/pluginTest/PluginInterface.h"

#include
"/Applications/QtCreator.app/Contents/Resources/gdbmacros/gdbmacros.cpp"

int main(int argc, char *argv[])

{

QCoreApplication a(argc, argv);

 QPluginLoader
pluginLoader("/Users/niklas/code/test/pluginTest/libplugintest.1.0.0.dylib");

QObject *plugin = pluginLoader.instance();

PluginInterface *pluginObj;

 // check whether it has been loaded or not

if(plugin)

{

pluginObj = qobject_cast<PluginInterface *>(plugin);

if(pluginObj)

{

qDebug() << "plugin loaded!";

qDebug() << "Plugin says: " << pluginObj->getMessage();

}

else

{

qDebug() << "could not typecast";

}

}

 // print error string

qDebug() << "error string: " << pluginLoader.errorString();

 return a.exec();

}



/Niklas


2009/2/24 Niklas Berglund <niklas.berglund at gmail.com>

> You guys really took some time to help me out. Thanks a lot!
> I added public, and tried the plugin template, but it still did not load.
> For some reason I tried the *Clean project* button in QtCreator and
> suddenly it worked!
>
> I had only done *C**lean all* before... So I suppose *Clean all* is a
> 'make clean' while *Clean project* re-runs qmake?
> So something must've been wrong in my .pro file.
> Tried to reproduce the problem for the benefit of other readers, but I
> couldn't.
>
> Thank you helpful people! :)
>
> /Niklas
>
> On Feb 24, 2009, at 10:14 AM, <Oliver.Knoll at comit.ch> <
> Oliver.Knoll at comit.ch> wrote:
>
> I added some slight modifications at the given links - not sure if they
> make a difference though.
> Basically I think you probably need to inherit "public" from your plugin
> interface:
> class MyPlugin : public QOBject, public MyPluginInterface {...};
>                                                ^^^^^
>
> Also, using the qmake TEMPLATE = plugin might help (not sure if that
> template still exists in Qt 4 tough - it was there for Qt 3)
>
> Does that help?
>
>
>
>
> On Feb 24, 2009, at 10:42 AM, Bruno Colombet wrote:
>
> Hello,
> Are you sure that the interface inheritance is public? (did not see class
> myplugin : public Interface).
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090224/77cd0ecd/attachment.html 


More information about the Qt-interest-old mailing list