QCanBus 类处理总线插件的注册和创建。 更多...
头: | #include <QCanBus> |
qmake: | QT += serialbus |
Since: | Qt 5.8 |
继承: | QObject |
该类在 Qt 5.8 引入。
QList<QCanBusDeviceInfo> | availableDevices (const QString & plugin , QString * errorMessage = nullptr) const |
QCanBusDevice * | createDevice (const QString & plugin , const QString & interfaceName , QString * errorMessage = nullptr) const |
QStringList | plugins () const |
QCanBus * | instance () |
QCanBus 在运行时加载 Qt CAN Bus 插件。将串行总线插件的所有权转移给加载程序。
返回可用接口,为 plugin . In case of failure, the optional parameter errorMessage returns a textual error description.
注意: 某些插件可能不支持 (或仅部分支持) 此函数。
For example, the following call returns a list of all available SocketCAN interfaces (which can be used for createDevice ()):
QString errorString; const QList<QCanBusDeviceInfo> devices = QCanBus::instance()->availableDevices( QStringLiteral("socketcan"), &errorString); if (!errorString.isEmpty()) qDebug() << errorString;
该函数在 Qt 5.9 引入。
另请参阅 createDevice ().
Creates a CAN bus device. plugin is the name of the plugin as returned by the plugins () 方法。 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:
QString errorString; QCanBusDevice *device = QCanBus::instance()->createDevice( QStringLiteral("socketcan"), QStringLiteral("vcan0"), &errorString); if (!device) qDebug() << errorString; else device->connectDevice();
注意: The interfaceName is plugin-dependent. See the corresponding plugin documentation for more information: CAN 总线插件 . To get a list of available interfaces, availableDevices () 可以使用。
另请参阅 availableDevices ().
[static]
QCanBus
*QCanBus::
实例
()
返回指针指向 QCanBus 类。对象会被加载 (若有必要)。 QCanBus 使用 Singleton (单例) 设计模式。
返回所有已加载插件的标识符列表。