QCanBus Class

The QCanBus class handles registration and creation of bus plugins. More...

Header: #include <QCanBus>
qmake: QT += serialbus
Since: Qt 5.8

Public Functions

QCanBusDevice *createDevice(const QString &plugin, const QString &interfaceName, QString *errorMessage = nullptr) const
QStringList plugins() const

Static Public Members

QCanBus *instance()

Detailed Description

The QCanBus class handles registration and creation of bus plugins.

QCanBus loads Qt CAN Bus plugins at runtime. The ownership of serial bus plugins is transferred to the loader.

Member Function Documentation

QCanBusDevice *QCanBus::createDevice(const QString &plugin, const QString &interfaceName, QString *errorMessage = nullptr) const

Creates a CAN bus device. plugin is the name of the plugin as returned by the plugins() method. interfaceName is the CAN bus interface name. In case of failure, the optional parameter errorMessage returns a textual error description.

Ownership of the returned plugin is transferred to the caller. Returns nullptr if no suitable device can be found.

For example, the following call would connect to the SocketCAN interface vcan0:


  QCanBusDevice *device = QCanBus::instance()->createDevice(
      QStringLiteral("socketcan"), QStringLiteral("vcan0"));
  device->connectDevice();

Note: The interfaceName is plugin-dependent. See the corresponding plugin documentation for more information: CAN Bus Plugins.

[static] QCanBus *QCanBus::instance()

Returns a pointer to the QCanBus class. The object is loaded if necessary. QCanBus uses the singleton design pattern.

QStringList QCanBus::plugins() const

Returns a list of identifiers for all loaded plugins.