Changes to Qt Remote Objects

Qt 6 是努力使框架更高效,且更易于使用的结果。

为兼容每个发行的所有公共 API,我们试着维护二进制和源代码。但是,为使 Qt 成为更优框架,一些改变是不可避免的。

In this topic we summarize those changes in Qt Remote Objects, and provide guidance to handle them.

API 变化

Functions taking const-ref QString changing to QStringView

QRemoteObjectHostBase::proxy , QRemoteObjectHostBase::reverseProxy and QRemoteObjectNode::instances now accept a QStringView 而不是 const QString & . The largest difference caused by this is that it no longer accepts implicit conversion from string literals (i.e. node.instances("abc"); ). Instead, you could use a UTF-16 string literal ( node.instances(u"abc") ).

Changes to classes for custom transport backend support

The "semi-private" IoDeviceBase , ServerIoDevice ,和 ClientIoDevice classes are now renamed to QtROIoDeviceBase , QtROServerIoDevice ,和 QtROClientIoDevice respectively, to be consistent with naming in Qt. They are also moved from the private qconnectionfactories_p.h header to qconnectionfactories.h .

注意: These classes are provided to give more flexibility for implementing custom communication protocols for Qt Remote Objects, but there are no source or binary compatibility guarantees for them. We recommend using the QRemoteObjectNode::addClientSideConnection () 和 QRemoteObjectHostBase::addHostSideConnection () methods, if you need support for external communication channels.

CMake changes

cmake instructions for calling repc and adding the generated .rep files to a CMake project have slightly changed. Instead of the qt5_generate_repc macro, you should now use qt6_add_repc_sources , qt6_add_repc_replicas and qt6_add_repc_merged functions. For example, the following code:

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

Should change to:

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

More detailed descriptions for these CMake functions can be found here .