Using Socketcan Plugin in Qt
-
wrote on 16 Dec 2020, 10:42 last edited by
Hi, I'm doing a work on can bus in qt creator. In this work, I need to use the socketcan plugin in qt. However, when I make a test as follows, I get an error "No such plugin: socketcan". I can see can0 when I write "ifconfig" on the Raspberry Pi terminal screen. But I can't use it in qt. How do you think I can fix this error and I can use socketcan in qt?
Qt code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtSerialBus>
#include <QCanBusDevice>
#include <QCanBus>
#include <QString>
#include <QDebug>MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);}
MainWindow::~MainWindow()
{
delete ui;}
void MainWindow::on_pushButton_clicked()
{
QString errorString;
QCanBusDevice *device = QCanBus::instance()->createDevice(
QStringLiteral("socketcan"), QStringLiteral("can0"), &errorString);
if (!device)
qDebug() << errorString;
else
device->connectDevice();
}The Error:
-
Hi, I'm doing a work on can bus in qt creator. In this work, I need to use the socketcan plugin in qt. However, when I make a test as follows, I get an error "No such plugin: socketcan". I can see can0 when I write "ifconfig" on the Raspberry Pi terminal screen. But I can't use it in qt. How do you think I can fix this error and I can use socketcan in qt?
Qt code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtSerialBus>
#include <QCanBusDevice>
#include <QCanBus>
#include <QString>
#include <QDebug>MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);}
MainWindow::~MainWindow()
{
delete ui;}
void MainWindow::on_pushButton_clicked()
{
QString errorString;
QCanBusDevice *device = QCanBus::instance()->createDevice(
QStringLiteral("socketcan"), QStringLiteral("can0"), &errorString);
if (!device)
qDebug() << errorString;
else
device->connectDevice();
}The Error:
Hi @safiye,
you need the plugin
libqtsocketcanbus.so
on your target.How did you install or deploy Qt there?
Regards
-
wrote on 16 Dec 2020, 13:54 last edited by
Thank you @aha_1980 ,
I have not installed plugin libqtsocketcanbus.so. I installed Qt on Raspberry Pi with "sudo apt-get install qtcreator". I did not do anything different for Socketcan. How can I install the plugin libqtsocketcanbus.so ?
-
Thank you @aha_1980 ,
I have not installed plugin libqtsocketcanbus.so. I installed Qt on Raspberry Pi with "sudo apt-get install qtcreator". I did not do anything different for Socketcan. How can I install the plugin libqtsocketcanbus.so ?
@safiye said in Using Socketcan Plugin in Qt:
sudo apt-get install qtcreator
This installs QtCreator and only some basic Qt stuff. If you want to install Qt search for Qt packages.
-
I installed sudo apt-get install libqt5serialbus5-dev and sudo apt-get install libqt5serialbus5 on Raspberry Pi. However, it gives the same error.
@safiye Do you build on RaspberryPi or do you do cross compiling?
-
wrote on 17 Dec 2020, 05:20 last edited by
@jsulm said in Using Socketcan Plugin in Qt:
@safiye Do you build on RaspberryPi or do you do cross compiling?
I'm building on a Raspberry Pi.
-
@safiye That will not work as long as you do not have libqtsocketcanbus.so plug-in. I don't know which package you have to install to get it. I'm not even sure the Linux distribution you're running on your device provides that at all (my Ubuntu 18.04 seems not to provide it). You could try to build it from source though.
-
@safiye That will not work as long as you do not have libqtsocketcanbus.so plug-in. I don't know which package you have to install to get it. I'm not even sure the Linux distribution you're running on your device provides that at all (my Ubuntu 18.04 seems not to provide it). You could try to build it from source though.
-
wrote on 17 Jul 2021, 00:19 last edited by
Hello, it is an old topic but someone can use it there, I had the same problem and nothing worked, but I solved it by adding the serialbus plugins because they will not be added they are libqt5serialbus5, it has to be installed:
sudo apt-get install libqt5serialbus5-plugins
Regards.