本页内容

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.canbus在Qt CAN Bus类中启用标准日志记录
qt.canbus.plugins启用Qt CAN Bus插件类中的低级日志记录。要为特定插件设置日志记录,请使用“qt.canbus.plugins.pluginname”。例如:“qt.canbus.plugins.socketcan”。“qt.canbus.plugins*”将影响所有插件。
qt.modbus启用Qt Modbus类中的标准日志记录
qt.modbus.lowlevel启用Qt Modbus类中的低级日志记录,包括单个数据包的内容

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

启用所有Qt Modbus日志记录的快捷方式是在 main() 函数中添加以下代码行:

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

示例

模块演变

“Qt SerialBus 的变更”列出了针对 Qt 6 系列所做的模块 API 和功能方面的主要变更。

许可

Qt SerialBus 由The Qt Company 提供商业许可。此外,它还遵循GNU 较小通用公共许可证第 3 版或GNU 通用公共许可证第 2 版。更多详细信息请参阅Qt 许可。

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