#ifndef JMEDIAPLAYERPLUGIN_H#define JMEDIAPLAYERPLUGIN_H#include <QObject>#include <JMediaPlayer.h>class JMediaPlayerPlugin : public QObject, public JMediaPlayer{Q_OBJECTQ_INTERFACES(JMediaPlayer)public: ~JMediaPlayerPlugin();};#endif
#include <QtGui>#include "JMediaPlayerPlugin.h"JMediaPlayerPlugin::~JMediaPlayerPlugin(){}Q_EXPORT_PLUGIN2(jmediaplayer, JMediaPlayerPlugin);
#ifndef JMEDIAPLAYER_H#define JMEDIAPLAYER_H#include <QString>class JMediaPlayer{public:// JMediaPlayer() {}; virtual ~JMediaPlayer() {};};QT_BEGIN_NAMESPACEQ_DECLARE_INTERFACE(JMediaPlayer,"myplugins.JMediaPlayer/1.0");QT_END_NAMESPACE#endif
TEMPLATE = libCONFIG += plugin staticHEADERS = JMediaPlayerPlugin.hSOURCES = JMediaPlayerPlugin.cppTARGET = $$qtLibraryTarget(jmediaplayer)
#include "../libjplayer/JMediaPlayerPlugin/src/JMediaPlayer.h"#include <QtPlugin>Q_IMPORT_PLUGIN(jmediaplayer);int main(int argc, char *argv[]){ .............
main.o: In function `__static_initialization_and_destruction_0(int, int)':main.cpp:(.text+0x1b): undefined reference to `qt_plugin_instance_jmediaplayer()'collect2: выполнение ld завершилось с кодом возврата 1
TEMPLATE = libCONFIG += staticlib
int JMediaPlayerPlugin::getVolume(){ return 14;}
virtual int getVolume();
JMediaPlayer * my_player = new JMediaPlayer(); qDebug() << "volume = " << my_player->getVolume();
mainwindow.o: In function `MainWindow::init()':mainwindow.cpp:(.text+0x5210): undefined reference to `vtable for JMediaPlayer'mainwindow.cpp:(.text+0x5219): undefined reference to `vtable for JMediaPlayer'../libjplayer/JMediaPlayerPlugin/src/libjmediaplayer.a(moc_JMediaPlayerPlugin.o):(.data.rel.ro._ZTI18JMediaPlayerPlugin[typeinfo for JMediaPlayerPlugin]+0x18): undefined reference to `typeinfo for JMediaPlayer'collect2: выполнение ld завершилось с кодом возврата 1
foreach (QObject *plugin, QPluginLoader::staticInstances()){ JMediaPlayer * my_player = qobject_cast<JMediaPlayer *>(plugin); if (my_player) qDebug() << my_player->getVolume(); }
../libjplayer/JMediaPlayerPlugin/src/libjmediaplayer.a(moc_JMediaPlayerPlugin.o):(.data.rel.ro._ZTI18JMediaPlayerPlugin[typeinfo for JMediaPlayerPlugin]+0x18): undefined reference to `typeinfo for JMediaPlayer'collect2: выполнение ld завершилось с кодом возврата 1
QMAKE_CXXFLAGS += -fno-rtti