QCanBus Class
QCanBus 类处理总线插件的注册和创建。更多
头文件: | #include <QCanBus> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS SerialBus) target_link_libraries(mytarget PRIVATE Qt6::SerialBus) |
qmake: | QT += serialbus |
继承: | QObject |
公共函数
(since 6.8) QList<QCanBusDeviceInfo> | availableDevices(QString *errorMessage = nullptr) const |
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() |
成员函数文档
[since 6.8]
QList<QCanBusDeviceInfo> QCanBus::availableDevices(QString *errorMessage = nullptr) const
返回所有插件的可用设备,即所有可用 CAN 接口。
如果失败,可选参数errorMessage 将返回文本错误描述。
注意: 某些插件可能不支持或仅部分支持该函数。
此函数在 Qt 6.8 中引入。
另请参阅 createDevice()。
QList<QCanBusDeviceInfo> QCanBus::availableDevices(const QString &plugin, QString *errorMessage = nullptr) const
返回plugin 的可用接口。如果失败,可选参数errorMessage 将返回文本错误描述。
注意: 某些插件可能不支持或仅部分支持此功能。
例如,以下调用将返回所有可用 SocketCAN 接口的列表(可用于createDevice()):
QStringerrorString;constQList<QCanBusDeviceInfo>devices= QCanBus::instance()->availableDevices( QStringLiteral("socketcan"), &errorString);if(!errorString.isEmpty()) qDebug() << errorString;
另见 createDevice().
QCanBusDevice *QCanBus::createDevice(const QString &plugin, const QString &interfaceName, QString *errorMessage = nullptr) const
创建 CAN 总线设备。plugin 是plugins() 方法返回的插件名称。interfaceName 是 CAN 总线接口名称。如果失败,可选参数errorMessage 将返回文本错误描述。
返回插件的所有权将转移给调用者。如果找不到合适的设备,则返回nullptr
。
例如,以下调用将连接到 SocketCAN 接口 vcan0:
QStringerrorString;QCanBusDevice*device = QCanBus::instance()->createDevice( QStringLiteral("socketcan")、 QStringLiteral("vcan0"), &errorString);if(!device) qDebug() << errorString; else device->connectDevice();
注: interfaceName 与插件有关。有关详细信息,请参阅相应的插件文档:CAN 总线插件。要获取可用接口列表,可使用availableDevices() 。
另请参阅 availableDevices() 。
[static]
QCanBus *QCanBus::instance()
返回指向QCanBus 类的指针。如有必要,将加载该对象。QCanBus 使用单例设计模式。
QStringList QCanBus::plugins() const
返回所有已加载插件的标识符列表。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.