QPluginLoader cannot load plugin [solved]
-
Hi,
Did you setup the plugin metadata correctly ? Do you call the Q_PLUGIN_METADATA macro ?
-
There are many possible sources of problem - from poorly written plugin to plugin built with different toolchain or different CRT.
-
Hi
I found this link useful
http://canvoki.net/Codders/qtpluginnotloading.htmlHTH
-
thank you for the answer..
yes, I called thia macro in the class that implements the plugin interface and then I got many errors like this:
error: undefined reference tovtable for InPluginInterface' error: undefined reference to
InPluginInterface::metaObject() const'
error: undefined reference to `InPluginInterface::qt_metacast(char const*)'etc. ....
the plugin is not for qt creator, its for a project that i do with qt creator
-
here is the code:
the h file of the interface:
#ifndef INPLUGININTERFACE_H
#define INPLUGININTERFACE_H
#pragma once#include <QtPlugin>
#include <QObject>
#include <QtCore>#include "ProcessingInterface.h"
#include "setting.h"
#include "msstorage.h"
#include "myplot.h"/**
@brief The InPluginInterface class
Factory of prossesingInterface
/
class InPluginInterface//:public QObject
{
// Q_OBJECT
public:
virtual ~InPluginInterface() = default;
virtual std::shared_ptr <ProcessingInterface> getProcessing
(myPlotInterface& plot,
QVector<ReducingInterface> reduceData)=0;
};Q_DECLARE_INTERFACE(InPluginInterface,"InPluginImp")
#endif // INPLUGININTERFACE_H
the h file of the class that implements the plugin:
#ifndef INPLUGINIMP_H
#define INPLUGINIMP_H#include <QtScript/QScriptEngine>
#include <QtScript/QScriptValue>
#include <memory>#include "inPluginInterface.h"
#include "ProcessingInterface.h"
#include "impprocessing.h"class Q_DECL_EXPORT InPluginImp :public QObject,public InPluginInterface
{
//Q_OBJECT
Q_PLUGIN_METADATA(IID "InPluginImp")
Q_INTERFACES(InPluginInterface)public:
InPluginImp();~InPluginImp()=default; // InPluginInterface interface std::shared_ptr<ProcessingInterface> getProcessing (myPlotInterface &plot, QVector<ReducingInterface *> msStorages) override;
};
#endif // INPLUGINIMP_H
the cpp file:
#include "inpluginimp.h"
InPluginImp::InPluginImp()
{}
std::shared_ptr <ProcessingInterface> InPluginImp::getProcessing
( myPlotInterface& plot,
QVector<ReducingInterface*> msStorages){
std::shared_ptr <ProcessingInterface> p=std::make_shared<impProcessing>(plot ,msStorages);
return p;
}the function that loading the plugin:
void Manager::loadPlugins()
{
pluginsDir = QDir(qApp->applicationDirPath());#if defined(Q_OS_WIN)
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
pluginsDir.cdUp();
#elif defined(Q_OS_MAC)
if (pluginsDir.dirName() == "MacOS") {
pluginsDir.cdUp();
pluginsDir.cdUp();
pluginsDir.cdUp();
}
#endif
//search the file that there the plugin declared
pluginsDir.cd("plugins");foreach (QString fileName, pluginsDir.entryList(QDir::Files)) { QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); QObject *plugin = loader.instance(); if (plugin) { pluginFileNames += fileName; } }
}
what is the problem here? why the QPluginLoader doesn't load the plugin? why the QLibraryPrivate::IsNotAPlugin (1)????
thanks!
-
the problem was that the plugin wasn't created good and the QPluginLoader wasn't recognized it as a plugin.
i returned the macro Q_OBJECT to InPluginImp class and i moved the inheritance from QOBJECT to the InPluginInterface class.
-
hi,
now i getting this error:
C:\workspace\16-5-15\src\mainProject\build-mainProject-Desktop_Qt_5_3_MinGW_32bit-Debug\VisualReceiverErrorsAnalysis\debug\moc_inpluginimp.cpp:149: error: undefined reference to `InPluginImp::InPluginImp()'and this one:
moc_inpluginimp.cpp:-1: error: undefined reference to `InPluginImp::getProcessing(myPlotInterface&, QVector<ReducingInterface*>)'collect2.exe:-1: error: error: ld returned 1 exit status
there is a solution for it?..
-
Did you properly implement both these functions ? Do you build the corresponding cpp file ?
-
When adding/removing the Q_OBJECT macro, do you re-run qmake before building ?