本页内容

变更说明Qt Remote Objects

Qt 6 的变更,是出于让该框架更高效、更易于使用的有意识努力的结果。

我们力求在每个版本中保持所有公共 API 的二进制和源代码兼容性。但为了使 Qt 成为更优秀的框架,某些变更在所难免。

在本主题中,我们将总结Qt Remote Objects 中的这些变更,并提供相应的处理指南。

API 变更

接受 const-ref QString 参数的函数改为接受 QStringView

QRemoteObjectHostBase::proxy,QRemoteObjectHostBase::reverseProxy 和QRemoteObjectNode::instances 现接受QStringView 参数,而非const QString & 。由此引发的最大变化是,这些函数不再接受字符串字面量的隐式转换(例如:node.instances("abc"); )。取而代之,您可以使用 UTF-16 字符串字面量(node.instances(u"abc") )。

为支持自定义传输后端而对类所做的更改

“半私有”类IoDeviceBase 、ServerIoDevice 和ClientIoDevice 现已分别重命名为QtROIoDeviceBase 、QtROServerIoDevice 和QtROClientIoDevice ,以与 Qt XML 中的命名保持一致。此外,这些类已从私有头文件qconnectionfactories_p.h 移至qconnectionfactories.h 。

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

CMake 变更

cmake 中关于调用repc以及将生成的.rep 文件添加到CMake项目的说明已略有更改。现在应使用qt6_add_repc_sources 、qt6_add_repc_replicas 和qt6_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 函数的更详细说明,请参见此处。

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