FilePluginInterface.h
Qt Code:
  1. #ifndef FILEPLUGININTERFACE_H
  2. #define FILEPLUGININTERFACE_H
  3.  
  4. #include "Geocache.h"
  5.  
  6. #include <QtPlugin>
  7. #include <QIODevice>
  8. #include <QString>
  9. #include <QList>
  10.  
  11. class FilePluginInterface {
  12. public:
  13. virtual ~FilePluginInterface() {}
  14.  
  15. virtual const char *getName() const throw() = 0;
  16. virtual const char *getVersion() const throw() = 0;
  17. virtual const char *getAuthor() const throw() = 0;
  18. virtual const char *getAuthorEmail() const throw() = 0;
  19. virtual bool isValid(QIODevice *source) = 0;
  20.  
  21. virtual QList<Geocache*> getAll(QIODevice *source) = 0;
  22. };
  23.  
  24. Q_DECLARE_INTERFACE(FilePluginInterface, "com.Something.Plugins.FilePlugin/1")
  25.  
  26. #endif // FILEPLUGININTERFACE_H
To copy to clipboard, switch view to plain text mode 

GeocachingComGpx.cpp
Qt Code:
  1. #include "../../../src/FilePluginInterface.h"
  2.  
  3. class GeocachingComGpx : public QObject, public FilePluginInterface {
  4. Q_OBJECT
  5. Q_INTERFACES(FilePluginInterface)
  6.  
  7. public:
  8. const char *getName() const throw();
  9. const char *getVersion() const throw();
  10. const char *getAuthor() const throw();
  11. const char *getAuthorEmail() const throw();
  12.  
  13. bool isValid(QIODevice *source);
  14.  
  15. QList<Geocache*> getAll(QIODevice *source);
  16. };
  17.  
  18. const char *GeocachingComGpx::getName() const throw()
  19. {
  20. return "Geocaching.com GPX Files";
  21. }
  22.  
  23. const char *GeocachingComGpx::getVersion() const throw()
  24. {
  25. return "0.1.0";
  26. }
  27.  
  28. const char *GeocachingComGpx::getAuthor() const throw()
  29. {
  30. return "James Marshall Hendrix";
  31. }
  32.  
  33. const char *GeocachingComGpx::getAuthorEmail() const throw()
  34. {
  35. return "jimi@hendrix.com";
  36. }
  37.  
  38. bool GeocachingComGpx::isValid(QIODevice *source)
  39. {
  40. Q_UNUSED(source);
  41. return true;
  42. }
  43.  
  44. QList<Geocache*> GeocachingComGpx::getAll(QIODevice *source)
  45. {
  46. Q_UNUSED(source);
  47. return QList<Geocache*>();
  48. }
  49.  
  50. Q_EXPORT_PLUGIN2(GeocachingComGpx, GeocachingComGpx);
To copy to clipboard, switch view to plain text mode 

GeocachingComGpx.pro
Qt Code:
  1. NAME = GeocachingComGpx
  2. VERSION = 0.1.0
  3. HEADERS += ../../../src/FilePluginInterface.h
  4. SOURCES += GeocachingComGpx.cpp
  5.  
  6. TEMPLATE = lib
  7. TARGET = $${NAME}
  8. DESTDIR = ../../../bin/plugins/file/
  9. DEPENDPATH += $$PWD
  10. INCLUDEPATH += $$PWD
  11. CONFIG += plugin
  12.  
  13. target.path = /usr/share/something/plugins/file/
  14.  
  15. INSTALLS += target
To copy to clipboard, switch view to plain text mode 

And when I'm trying to load a plugin:

Qt Code:
  1. QStringList files = path.entryList(QDir::Files);
  2.  
  3. for (QStringList::iterator it2 = files.begin(); it2 != files.end(); it2++) {
  4. QPluginLoader pluginLoader(path.absoluteFilePath(*it2));
  5. QObject *plugin = pluginLoader.instance();
  6.  
  7. if (plugin) {
  8. filePlugins.append(qobject_cast<FilePluginInterface*>(plugin));
  9. qDebug() << "Loaded plugin" << filePlugins.last()->getName()
  10. << filePlugins.last()->getVersion();
  11. } else {
  12. qDebug() << pluginLoader.errorString();
  13. }
  14. }
To copy to clipboard, switch view to plain text mode 

pluginLoader.errorString() gives me

Qt Code:
  1. /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