Unsolved create a custom canbus plugin
-
Hi all,
I'm trying to implement a custom canbus plugin. Following this qt doc: https://doc.qt.io/qt-5/qtcanbus-backends.htmland opening source file like "socketcanbus" plugin, I created a shared library plugin, which is compiling correctly and is giving me the .dll file at the end of build. Here following my .pro file:
####################################################################
TARGET = cnhvirtualcanbusQT += core serialbus
TEMPLATE = lib
CONFIG += pluginCONFIG += c++14
DEFINES -= UNICODE
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES +=
camelplugin.cpp
canvirtualconnection.cppHEADERS +=
canvirtualconnection.hDISTFILES += CamelPlugin.json
Default rules for deployment.
unix {
target.path = $$[QT_INSTALL_PLUGINS]/generic
}
!isEmpty(target.path): INSTALLS += targetTARGET = $$qtLibraryTarget(cnhvirtualcanbus)
DESTDIR = ..\buildtarget.path = ..\build
INSTALLS += targetwin32: LIBS += -L$$PWD/lib/ -lQtCanSim
INCLUDEPATH += $$PWD/.
DEPENDPATH += $$PWD/.##########################################################
Here the .cpp interface (I don't have a corresponding .h, only cpp implementation):
################################################################
#include <QtSerialBus/qcanbus.h>
#include <QtSerialBus/qcanbusdevice.h>
#include <QtSerialBus/qcanbusfactory.h>#include "canvirtualconnection.h"
class camelPlugin : public QObject, public QCanBusFactoryV2
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QCanBusFactoryV2" FILE "CamelPlugin.json")
Q_INTERFACES(QCanBusFactoryV2)
public://reimplement pure virtual function QList<QCanBusDeviceInfo> availableDevices(QString *errorMessage) const override { Q_UNUSED(errorMessage); QList<QCanBusDeviceInfo> result; return result; } QCanBusDevice *createDevice(const QString &interfaceName, QString *errorMessage) const override { Q_UNUSED(errorMessage); Q_UNUSED(interfaceName); auto device = new CanVirtualConnection(); return device; }
};
######################################################now, in my application, which is supposed to load the plugin, I have this lines of code in main.cpp:
#################################################################
QCoreApplication::addLibraryPath("C:/Users/Gabriele/Desktop/CamelPlugin/build");QPluginLoader* camelPlugin = new QPluginLoader("cnhvirtualcanbusd"); if(!camelPlugin->load()) { qDebug()<<camelPlugin->errorString(); }
######################################################
When I run the application I got this error: "Failed to extract plugin meta data from 'C:/Users/Gabriele/Desktop/CamelPlugin/build/cnhvirtualcanbusd.dll'"
So, my plugin is reached but cannot be loaded. Anyone can help me to solve this issue?
I guess the problem is in re-implementing the "QCanBusFactoryV2", but I have no idea how to fix this.Thanks for support