Congratulations to our 2022 Qt Champions!

How to develop CAN plugin while debugging

  • Hi everybody!

    I would like to develop a canbus plugin, to be compatible with Qt interface of QCanBusDevice .
    To do so i created a project, in which main folder I have this *.pro file:

    TEMPLATE = subdirs
    SUBDIRS = can canusb_vcp
    can.depends = canusb_vcp

    then i have two subdirectories, one named can, that is simply the canbus example for qt, but with *.pro file modified like so:

    QT += serialbus widgets serialport
    TARGET = can
    TEMPLATE = app
    CONFIG += debug_and_release
    SOURCES += \
        bitratebox.cpp \
        connectdialog.cpp \
        main.cpp \
        mainwindow.cpp \
    HEADERS += \
        bitratebox.h \
        connectdialog.h \
        mainwindow.h \
    FORMS   += mainwindow.ui \
        connectdialog.ui \
    RESOURCES += can.qrc

    as you can see i am including the plugin i am trying to implement

    and then the can plugin has one *.pro file, and one *.pri file:

    QT += serialbus serialport
    TEMPLATE = lib
    CONFIG += shared
    CONFIG += debug_and_release
    TARGET = canusb_vcp
    SOURCES += \
        canusbvcpplugin.cpp \
    HEADERS += \
        canusbvcpplugin.h \
        canusbvcpbackend.h \
    DISTFILES += \


    LIBTARGET = canusb_vcp
    BASEDIR   = $${PWD}
    INCLUDEPATH *= $${BASEDIR}/canusb_vcp
    LIBS += -L$${DESTDIR} -lcanusb_vcp

    this way, after compilation of the project, i can copy the canusb_vcp.dll and put it in the folder of can example executable.
    Then, it runs ok.

    At this point, i would like to continue with the development, but at the same time i would like to debug.
    Can anyone tell me how could i debug a plugin, having a project structured like this? Maybe i should structure it differently?

    Thanks in advance

  • Lifetime Qt Champion

    Hi @federdalla,

    I'm the maintainer of QtCanBus, and I'd love to integrate this plugin in the official repo. Do you have any plans open-sourcing it?

    Regarding your problem: I think it should be enough to add LIBS += -L<path/to/compiled-plugin> to the file. Qt Creator then setup the library search path so when running the CAN Example, the plugin can be loaded.

    You have already set up the dependencies correctly, so the plugin should be rebuild after changes before starting the example.

    Best regards, and I hope we can integrate your plugin into Qt soon :)


  • Hi @aha_1980

    thank you for your answer, I will try your solution as soon as I can.

    I think it would be ok for me to open source it.
    If you could provide me info on how I can contribute, it would be easier.

    Maybe we can get in touch with private messages.



  • Lifetime Qt Champion

    Hi @federdalla,

    I'll be very glad to help you - just feel free ping me. I'll just be a bit busy this week...

    I think you should get something up and running first before we talk about the steps to get the plugin merged.

    Best regards

Log in to reply