Qt Remote Objects

Qt 6 是有意识地使框架更高效、更易用的结果。

我们努力在每个版本中保持所有公共 API 的二进制和源代码兼容性。但为了使 Qt 成为一个更好的框架,有些改动是不可避免的。

在本专题中,我们总结了Qt Remote Objects 中的这些变化,并提供了处理这些变化的指导。

API 变化

使用 Const-ref QString 的函数更改为 QStringView

QRemoteObjectHostBase::proxy现在,QRemoteObjectHostBase::reverseProxyQRemoteObjectNode::instances 接受QStringView 而不是const QString & 。由此造成的最大不同是,它不再接受字符串字面量的隐式转换(即node.instances("abc"); )。相反,您可以使用 UTF-16 字面字符串 (node.instances(u"abc"))。

自定义传输后端支持类的更改

半私有 "的IoDeviceBaseServerIoDeviceClientIoDevice 类现在分别重命名为QtROIoDeviceBaseQtROServerIoDeviceQtROClientIoDevice ,以便与 Qt XML 中的命名一致。它们也从私有qconnectionfactories_p.h 头移至qconnectionfactories.h

注意: 提供这些类是为了给Qt Remote Objects 实现自定义通信协议提供更大的灵活性,但它们没有源代码或二进制兼容性保证。如果您需要外部通信渠道支持,我们建议您使用QRemoteObjectNode::addClientSideConnection() 和QRemoteObjectHostBase::addHostSideConnection() 方法。

CMake 更改

调用repc并将生成的.rep 文件添加到 CMake 项目的cmake 说明略有改动。现在应使用qt6_add_repc_sourcesqt6_add_repc_replicasqt6_add_repc_merged 函数,而不是qt5_generate_repc 宏。例如,以下代码

set(SOURCES
    main.cpp
    simpleswitch.cpp
)

qt5_generate_repc(SOURCES simpleswitch.rep SOURCE)
add_executable(directconnectserver ${SOURCES})

应改为

set(SOURCES
    main.cpp
    simpleswitch.cpp
)
add_executable(directconnectserver ${SOURCES})
qt6_add_repc_sources(directconnectserver simpleswitch.rep)

有关这些 CMake 函数的更详细说明,请点击此处

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