FilePluginInterface.h
#ifndef FILEPLUGININTERFACE_H
#define FILEPLUGININTERFACE_H
#include "Geocache.h"
#include <QtPlugin>
#include <QIODevice>
#include <QString>
#include <QList>
class FilePluginInterface {
public:
virtual ~FilePluginInterface() {}
virtual const char *getName() const throw() = 0;
virtual const char *getVersion() const throw() = 0;
virtual const char *getAuthor() const throw() = 0;
virtual const char *getAuthorEmail() const throw() = 0;
virtual QList<Geocache
*> getAll
(QIODevice *source
) = 0;
};
Q_DECLARE_INTERFACE(FilePluginInterface, "com.Something.Plugins.FilePlugin/1")
#endif // FILEPLUGININTERFACE_H
#ifndef FILEPLUGININTERFACE_H
#define FILEPLUGININTERFACE_H
#include "Geocache.h"
#include <QtPlugin>
#include <QIODevice>
#include <QString>
#include <QList>
class FilePluginInterface {
public:
virtual ~FilePluginInterface() {}
virtual const char *getName() const throw() = 0;
virtual const char *getVersion() const throw() = 0;
virtual const char *getAuthor() const throw() = 0;
virtual const char *getAuthorEmail() const throw() = 0;
virtual bool isValid(QIODevice *source) = 0;
virtual QList<Geocache*> getAll(QIODevice *source) = 0;
};
Q_DECLARE_INTERFACE(FilePluginInterface, "com.Something.Plugins.FilePlugin/1")
#endif // FILEPLUGININTERFACE_H
To copy to clipboard, switch view to plain text mode
GeocachingComGpx.cpp
#include "../../../src/FilePluginInterface.h"
class GeocachingComGpx
: public QObject,
public FilePluginInterface
{ Q_OBJECT
Q_INTERFACES(FilePluginInterface)
public:
const char *getName() const throw();
const char *getVersion() const throw();
const char *getAuthor() const throw();
const char *getAuthorEmail() const throw();
};
const char *GeocachingComGpx::getName() const throw()
{
return "Geocaching.com GPX Files";
}
const char *GeocachingComGpx::getVersion() const throw()
{
return "0.1.0";
}
const char *GeocachingComGpx::getAuthor() const throw()
{
return "James Marshall Hendrix";
}
const char *GeocachingComGpx::getAuthorEmail() const throw()
{
return "jimi@hendrix.com";
}
bool GeocachingComGpx
::isValid(QIODevice *source
) {
Q_UNUSED(source);
return true;
}
QList<Geocache
*> GeocachingComGpx
::getAll(QIODevice *source
){
Q_UNUSED(source);
return QList<Geocache*>();
}
Q_EXPORT_PLUGIN2(GeocachingComGpx, GeocachingComGpx);
#include "../../../src/FilePluginInterface.h"
class GeocachingComGpx : public QObject, public FilePluginInterface {
Q_OBJECT
Q_INTERFACES(FilePluginInterface)
public:
const char *getName() const throw();
const char *getVersion() const throw();
const char *getAuthor() const throw();
const char *getAuthorEmail() const throw();
bool isValid(QIODevice *source);
QList<Geocache*> getAll(QIODevice *source);
};
const char *GeocachingComGpx::getName() const throw()
{
return "Geocaching.com GPX Files";
}
const char *GeocachingComGpx::getVersion() const throw()
{
return "0.1.0";
}
const char *GeocachingComGpx::getAuthor() const throw()
{
return "James Marshall Hendrix";
}
const char *GeocachingComGpx::getAuthorEmail() const throw()
{
return "jimi@hendrix.com";
}
bool GeocachingComGpx::isValid(QIODevice *source)
{
Q_UNUSED(source);
return true;
}
QList<Geocache*> GeocachingComGpx::getAll(QIODevice *source)
{
Q_UNUSED(source);
return QList<Geocache*>();
}
Q_EXPORT_PLUGIN2(GeocachingComGpx, GeocachingComGpx);
To copy to clipboard, switch view to plain text mode
GeocachingComGpx.pro
NAME = GeocachingComGpx
VERSION = 0.1.0
HEADERS += ../../../src/FilePluginInterface.h
SOURCES += GeocachingComGpx.cpp
TEMPLATE = lib
TARGET = $${NAME}
DESTDIR = ../../../bin/plugins/file/
DEPENDPATH += $$PWD
INCLUDEPATH += $$PWD
CONFIG += plugin
target.path = /usr/share/something/plugins/file/
INSTALLS += target
NAME = GeocachingComGpx
VERSION = 0.1.0
HEADERS += ../../../src/FilePluginInterface.h
SOURCES += GeocachingComGpx.cpp
TEMPLATE = lib
TARGET = $${NAME}
DESTDIR = ../../../bin/plugins/file/
DEPENDPATH += $$PWD
INCLUDEPATH += $$PWD
CONFIG += plugin
target.path = /usr/share/something/plugins/file/
INSTALLS += target
To copy to clipboard, switch view to plain text mode
And when I'm trying to load a plugin:
for (QStringList::iterator it2
= files.
begin(); it2
!= files.
end(); it2
++) { QObject *plugin
= pluginLoader.
instance();
if (plugin) {
filePlugins.append(qobject_cast<FilePluginInterface*>(plugin));
qDebug() << "Loaded plugin" << filePlugins.last()->getName()
<< filePlugins.last()->getVersion();
} else {
qDebug() << pluginLoader.errorString();
}
}
QStringList files = path.entryList(QDir::Files);
for (QStringList::iterator it2 = files.begin(); it2 != files.end(); it2++) {
QPluginLoader pluginLoader(path.absoluteFilePath(*it2));
QObject *plugin = pluginLoader.instance();
if (plugin) {
filePlugins.append(qobject_cast<FilePluginInterface*>(plugin));
qDebug() << "Loaded plugin" << filePlugins.last()->getName()
<< filePlugins.last()->getVersion();
} else {
qDebug() << pluginLoader.errorString();
}
}
To copy to clipboard, switch view to plain text mode
pluginLoader.errorString() gives me
/some/nice/path/bin/plugins/file/libGeocachingComGpx.so: undefined symbol: _ZTV16GeocachingComGpx
/some/nice/path/bin/plugins/file/libGeocachingComGpx.so: undefined symbol: _ZTV16GeocachingComGpx
To copy to clipboard, switch view to plain text mode
_ZTV16GeocachingComGpx seems to be the symbol of my plugin's class (I looked into binary, methods symbols are prepended by it). Why it's missing from the binary? And if it's not, what's going on then?
Thanks for your time
Bookmarks