Qt SerialBus 的变更
Qt 6 是为了使框架更高效、更易于使用而进行的有意识努力的成果。 我们力求在每个版本中保持所有公开 API 的二进制和源代码兼容性。但为了使 Qt 成为更优秀的框架,某些变更在所难免。在本主题中,我们将总结 Qt SerialBus 模块中的这些变更,并提供相应的处理指南。
变更概述
总体而言,Qt SerialBus 模块与 Qt 5 版本在源码层面保持兼容,该库的用户通常无需对项目进行任何修改,或仅需进行微调即可继续使用。
构建系统
与 Qt 6 的整体情况一致,Qt SerialBus 模块除了支持 qmake 之外,还支持 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 现在使用独立类型 `FrameId`,该类型是 `quint32` 的 `typedef`,因此现有代码应仍可正常运行。不过,建议在升级时使用 `FrameId `。
Qt Modbus
QModbusRtuSerialMaster 和 QModbusRtuSerialSlave 的重命名
根据 Modbus 组织的建议,类QModbusRtuSerialMaster 已重命名为QModbusRtuSerialClient ,类QModbusRtuSerialSlave 已重命名为QModbusRtuSerialServer 。建议在新代码或移植的代码中使用新的类名,以符合 Modbus 的命名规范。
© 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.