Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. create a custom canbus plugin
Forum Updated to NodeBB v4.3 + New Features

create a custom canbus plugin

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
1 Posts 1 Posters 399 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gabriele11_
    wrote on 21 Jun 2020, 16:00 last edited by
    #1

    Hi all,
    I'm trying to implement a custom canbus plugin. Following this qt doc: https://doc.qt.io/qt-5/qtcanbus-backends.html

    and 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 = cnhvirtualcanbus

    QT += core serialbus

    TEMPLATE = lib
    CONFIG += plugin

    CONFIG += c++14

    DEFINES -= UNICODE

    DEFINES += QT_DEPRECATED_WARNINGS

    SOURCES +=
    camelplugin.cpp
    canvirtualconnection.cpp

    HEADERS +=
    canvirtualconnection.h

    DISTFILES += CamelPlugin.json

    Default rules for deployment.

    unix {
    target.path = $$[QT_INSTALL_PLUGINS]/generic
    }
    !isEmpty(target.path): INSTALLS += target

    TARGET = $$qtLibraryTarget(cnhvirtualcanbus)
    DESTDIR = ..\build

    target.path = ..\build
    INSTALLS += target

    win32: 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

    1 Reply Last reply
    0

    1/1

    21 Jun 2020, 16:00

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved