Qt SerialBus 的变化

Qt 6 是有意识地提高框架效率和易用性的结果。我们努力在每个版本中保持所有公共 API 的二进制和源代码兼容性。但为了使 Qt 成为一个更好的框架,有些改动是不可避免的。在本主题中,我们将总结 Qt SerialBus 模块中的这些变化,并提供处理这些变化的指导。

变化概述

一般来说,Qt SerialBus 模块的源代码与 Qt 5 版本兼容,该库的用户应能继续使用,无需对其项目进行任何改动或微小改动。

构建系统

与 Qt 6 大致相同,除了 qmake 之外,Qt SerialBus 模块还支持 CMake。

API 变化

Qt CAN 总线

删除 QCanBusFactoryV2

在 Qt 6 中,QCanBusFactoryV2 已被移除,不再是公共 API 的一部分。取而代之的是QCanBusFactory 获得了额外的方法QCanBusFactory::availableDevices ,该方法需要由QCanBusFactory 的子类实现。

对 QCanBusDevice 的修改

QCanBusDevice 的变更如下:

  • setConfigurationParameter() 和 configurationParameter() 现在使用不同类型的 ConfigurationKey,而不是 int。
  • 函数 resetController()、hasBusStatus() 和 busStatus() 现在是虚拟函数。由于二进制兼容的原因,它们在 Qt 5 中一直是内部回调。
  • 使用其中一个私有 API 函数 QCanBusDevice::createDeviceInfo() 的定制插件需要进行少量修改,因为这些函数现在将plugin 名称作为第一个参数,并略微采用了参数列表。

对 QCanBusFrame 的修改

QCanBusFrame 的修改,现在它使用了不同的类型 ,这是 quint32 的类型定义,因此现有代码仍可正常工作。无论如何,建议在升级时使用 。FrameId FrameId

Qt Modbus

重新命名 QModbusRtuSerialMaster 和 QModbusRtuSerialSlave

根据 Modbus 组织的建议,类QModbusRtuSerialMaster 已重命名为QModbusRtuSerialClient ,类QModbusRtuSerialSlave 已重命名为QModbusRtuSerialServer 。建议在新代码或移植代码中使用新的类名,以符合 Modbus 命名方案。

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