Using Socketcan Plugin in Qt
-
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:
-
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.
-
@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.
-
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.