Qt Serial Bus

Qt Serial Bus API 提供了访问 CAN、ModBus 等各种工业串行总线和协议的类和函数。

开始使用

要在 CMake 中使用该模块,可使用find_package() 命令在Qt6 软件包中找到所需的模块组件:

find_package(Qt6 COMPONENTS SerialBus REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::SerialBus)

要使用 qmake 制作模块,可在项目的 .pro 文件中将模块添加为QT 变量的值:

QT += serialbus

支持的总线和协议

API 参考资料

这些是 API 参考资料的链接。

日志类别

QtSerialBus 模块导出以下logging categories

日志类别说明
qt.canbusQt CAN Bus类中启用标准日志记录
qt.canbus.pluginsQt CAN Bus插件类中启用低级日志记录。要为特定插件设置日志,请使用 "qt.canbus.plugins.pluginname",例如 "qt.canbus.plugins.socketcan"。"qt.canbus.plugins*"会影响所有插件。
qt.modbusQt Modbus类中启用标准日志记录
qt.modbus.lowlevelQt Modbus类中启用低级日志,包括单个数据包内容

日志类别可用于为QtSerialBus 启用额外的警告和调试输出。有关日志记录的更多详细信息,请参阅QLoggingCategory

启用所有Qt Modbus日志的快速方法是在 main() 函数中添加以下一行:

QLoggingCategory::setFilterRules(QStringLiteral("qt.modbus* = true"));

示例

模块演变

Qt SerialBus 的变化列出了 Qt 6 系列在模块 API 和功能方面的重要变化。

© 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.