QRemoteObjectHostBase Class
QRemoteObjectHostBase 클래스는 Host 및 RegistryHost 클래스에 공통된 기본 기능을 제공합니다. 더 보기...
헤더: | #include <QRemoteObjectHostBase> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS RemoteObjects) target_link_libraries(mytarget PRIVATE Qt6::RemoteObjects) |
qmake: | QT += remoteobjects |
상속합니다: | QRemoteObjectNode |
상속 대상 |
공용 유형
enum | AllowedSchemas { BuiltInSchemasOnly, AllowExternalRegistration } |
공용 함수
void | addHostSideConnection(QIODevice *ioDevice) |
bool | disableRemoting(QObject *remoteObject) |
bool | enableRemoting(ObjectType *object) |
bool | enableRemoting(QObject *object, const QString &name = QString()) |
bool | enableRemoting(QAbstractItemModel *model, const QString &name, const QList<int> roles, QItemSelectionModel *selectionModel = nullptr) |
bool | proxy(const QUrl ®istryUrl, const QUrl &hostUrl = {}, QRemoteObjectHostBase::RemoteObjectNameFilter filter = [](QStringView, QStringView) {return true; }) |
bool | reverseProxy(QRemoteObjectHostBase::RemoteObjectNameFilter filter = [](QStringView, QStringView) {return true; }) |
재구현된 공용 함수
virtual void | setName(const QString &name) override |
상세 설명
QRemoteObjectHostBase는 직접 인스턴스화할 수 없는 베이스 클래스입니다. 모든 호스트 노드(Host 및 RegistryHost)가 공유하는 enableRemoting 및 disableRemoting 기능과 원격 객체 네트워크에 소스 객체를 노출하는 데 필요한 로직을 제공합니다.
멤버 유형 문서
enum QRemoteObjectHostBase::AllowedSchemas
이 열거형은 노드가 hostUrl에 대해 인식할 수 없는 스키마가 있는 URL을 허용할지 여부를 지정하는 데 사용됩니다. 기본적으로 알려진 스키마가 있는 URL만 허용되지만 AllowExternalRegistration
을 사용하면 레지스트리에서 외부(QtRO로) URL을 클라이언트 노드에 전달할 수 있습니다.
상수 | 값 | 설명 |
---|---|---|
QRemoteObjectHostBase::BuiltInSchemasOnly | 0 | hostUrl을 QtRO 지원 스키마로만 설정하도록 허용합니다. 이 값이 기본값이며, 인식할 수 없는 스키마를 제공하면 노드 오류가 설정됩니다. |
QRemoteObjectHostBase::AllowExternalRegistration | 1 | 제공된 스키마는 외부 스키마로 등록됩니다. |
QRemoteObjectHost 를참조하세요 .
멤버 함수 문서
void QRemoteObjectHostBase::addHostSideConnection(QIODevice *ioDevice)
외부 QIODevices를 통해 QRemoteObjectHost::enableRemoting() 오브젝트를 소스하려면 Qt Remote Objects 각 노드 간의 통신 채널( QIODevice)에 액세스해야 합니다. ioDevice 을 입력으로 받아 소스 측에서 이를 활성화하는 것은 addHostSideConnection() 호출입니다. enableRemoting () 호출은 addHostSideConnection을 호출하지 않고도 계속 작동하지만 노드는 복제 노드에 대한 연결이 제공되지 않으면 소스 오브젝트를 공유할 수 없습니다. 이 함수를 호출하기 전에 고유 URL과 AllowExternalRegistration 을 사용하여 setHostUrl()를 호출해야 합니다.
addClientSideConnection 를참조하세요 .
[invokable]
bool QRemoteObjectHostBase::disableRemoting(QObject *remoteObject)
QObject remoteObject 에 대한 원격 액세스를 비활성화합니다. 현재 노드가 클라이언트 노드이거나 remoteObject 이 등록되지 않은 경우 false
을 반환하고, 소스 개체에 대해 원격이 성공적으로 비활성화되면 true
을 반환합니다.
경고: 이 메서드를 호출한 후에는 이 객체의 복제본이 더 이상 유효하지 않습니다.
참고: 이 함수는 메타 객체 시스템과 QML을 통해 호출할 수 있습니다. Q_INVOKABLE 을 참조하세요.
enableRemoting()도 참조하세요 .
template <template <typename> typename ApiDefinition, typename ObjectType> bool QRemoteObjectHostBase::enableRemoting(ObjectType *object)
이 템플릿 함수 오버로드를 사용하면 호스트 노드가 지정된(그리고 컴파일 타임에 확인된) 인터페이스를 통해 QObject object 에 원격 액세스를 제공할 수 있습니다. 이 오브젝트를 호스팅하는 노드에 연결된 클라이언트 노드는 이 소스의 복제본을 얻을 수 있습니다.
예시를 통해 이를 가장 잘 설명할 수 있습니다:
#include "rep_TimeModel_source.h" MinuteTimer timer; hostNode.enableRemoting<MinuteTimerSourceAPI>(&timer);
여기서 MinuteTimerSourceAPI는 TimeModel.rep 파일에 정의된 시그널/슬롯/프로퍼티 집합입니다. 컴파일 시간 확인을 통해 QObject 입력이 요청된 API를 노출할 수 있는지 확인하며, 그렇지 않으면 컴파일에 실패합니다. 이를 통해 object 인터페이스의 하위 집합이 노출될 수 있으며, 신호/슬롯 연결에서 지원되는 변환 유형이 허용됩니다.
현재 노드가 클라이언트 노드이거나 QObject 이 이미 원격으로 등록되어 있는 경우 false
을 반환하고, QObject 에 대해 원격이 성공적으로 활성화된 경우 true
을 반환합니다.
disableRemoting()도 참조하세요 .
[invokable]
bool QRemoteObjectHostBase::enableRemoting(QObject *object, const QString &name = QString())
호스트 노드가 QObject object 에 대한 원격 액세스를 동적으로 제공할 수 있도록 합니다. 이 오브젝트를 호스팅하는 노드에 연결된 클라이언트 노드는 이 소스의 복제본을 얻을 수 있습니다.
name 옵션은 QRemoteObjectNode::acquire()를 사용하여 QObject 을 획득할 수 있는 조회 이름을 정의합니다. 명시적으로 설정하지 않으면 QCLASSINFO_REMOTEOBJECT_TYPE에 지정된 이름이 사용됩니다. QObject 에 대해 이러한 매크로가 정의되지 않은 경우 QObject::objectName()가 사용됩니다.
현재 노드가 클라이언트 노드이거나 QObject 이 이미 원격으로 등록되어 있는 경우 false
을 반환하고, 동적 QObject 에 대해 원격이 성공적으로 활성화된 경우 true
을 반환합니다.
참고: 이 함수는 메타 객체 시스템과 QML을 통해 호출할 수 있습니다. Q_INVOKABLE 을 참조하세요.
disableRemoting()도 참조하세요 .
bool QRemoteObjectHostBase::enableRemoting(QAbstractItemModel *model, const QString &name, const QList<int> roles, QItemSelectionModel *selectionModel = nullptr)
이 enableRemoting()의 오버로드는 QAbstractItemModel 유형(또는 QAbstractItemModel 에서 파생된 모든 유형)에만 해당됩니다. 이는 서로 다른 프로세스에서 모델과 모델에 대한 HMI를 사용하려는 경우에 유용합니다.
세 가지 필수 매개 변수는 model 자체, 모델을 조회할 name, 그리고 레플리카 측에 노출되어야 하는 roles 입니다. 소스와 복제본 간의 선택을 동기화하려면 selectionModel 매개변수(선택 사항)를 사용할 수 있습니다. 이 옵션은 단일 복제본을 사용하는 경우에만 권장됩니다.
백그라운드에서 Qt Remote Objects 은 가능한 경우 데이터() 조회를 일괄 처리하고 데이터를 미리 가져와 모델 상호 작용을 최대한 반응성 있게 만듭니다.
현재 노드가 클라이언트 노드이거나 QObject 이 이미 원격으로 등록되어 있는 경우 false
을 반환하고, QAbstractItemModel 에 대해 원격이 성공적으로 활성화된 경우 true
을 반환합니다.
disableRemoting()도 참조하세요 .
bool QRemoteObjectHostBase::proxy(const QUrl ®istryUrl, const QUrl &hostUrl = {}, QRemoteObjectHostBase::RemoteObjectNameFilter filter = [](QStringView, QStringView) {return true; })
다른 네트워크에서 원격 오브젝트 전달
프록시 기능은 여러 네트워크에서 소스 오브젝트를 공유하려는 경우에 유용합니다. 예를 들어, 대상 전용 연결(예: 로컬)을 사용하는 임베디드 대상이 있고 동일한 대상 중 일부를 외부에서 사용할 수 있도록 하려는 경우입니다.
구체적인 예로, 대상 하드웨어에서 레지스트리를 사용하여 서로 통신하는 프로세스 집합이 있고, 레지스트리는 "local:registry"에 있으며, 소스 개체를 보관하는 노드는 "local:MyHost"에 있는 별도의 프로세스를 사용한다고 가정해 보겠습니다. 이러한 오브젝트에 액세스하고 싶지만 tcp를 통해 액세스하려면 다음과 같이 새 proxyNode를 만들 수 있습니다:
// myInternalHost is a node only visible on the device... QRemoteObjectHost myInternalHost("local:MyHost"); myInternalHost.enableRemoting<SomeObject>(&someObject); // Regular host node, listening on port 12123, so visible to other // devices QRemoteObjectHost proxyNode("tcp://localhost:12123"); // Enable proxying objects from nodes on the local machine's internal // QtRO bus proxyNode.proxy("local:registry");
그리고 다른 기기에서 또 다른 노드를 생성합니다:
// NB: localhost resolves to a different ip address than proxyNode QRemoteObjectHost nodeOnRemoteDevice("tcp://localhost:23234"); // Connect to the target's proxyNode directly, or use a tcp registry... nodeOnRemoteDevice.connectToNode("tcp://<target device>:12123"); // Because of the proxy, we can get the object over tcp/ip port 12123, // even though we can't connect directly to "local:MyHost" SomeObject *so = nodeOnRemoteDevice.acquire<SomeObject>();
이렇게 하면 (내부적으로) proxyNode에 노드가 생성되고, 이 노드는 (다시 내부적으로/자동적으로) 제공된 레지스트리에 연결됩니다(이 예에서는 registryUrl 매개변수인 "local:registry"로 지정됨). local:registry가 remoteObjectAdded 신호를 보낼 때마다 QRemoteObjectSourceLocation
은 프록시 호출에 지정된 filter 으로 전달됩니다. 이 메서드가 참을 반환하면(기본 필터는 필터링 없이 단순히 참을 반환합니다) 내부 노드에서 객체를 획득()하고 (복제본이 초기화되면) enableRemoting()가 proxyNode에서 호출됩니다.
hostUrl 이 제공되면( reverseProxy 을 활성화하는 데 필요하지만 그렇지 않은 경우 필요하지 않음) 내부 노드는 제공된 주소로 구성된 QRemoteObjectHost 노드가 됩니다. hostUrl 이 제공되지 않으면 내부 노드는 QRemoteObjectNode (HostNode가 아닌)이 됩니다.
내부 노드에서 객체를 가져온 경우 true
을 반환합니다.
reverseProxy()도 참조하세요 .
bool QRemoteObjectHostBase::reverseProxy(QRemoteObjectHostBase::RemoteObjectNameFilter filter = [](QStringView, QStringView) {return true; })
원격 객체를 다른 네트워크로 전달합니다.
reverseProxy() 함수를 사용하면 proxy() 기능을 확장하여 사실상 프록시 기능을 "역방향"으로 미러링할 수 있습니다. 노드 통신은 대칭이 아니므로 한쪽에서는 소스 개체로 enableRemoting()를 호출하고 다른 쪽에서는 복제본을 가져오기 위해 acquire()를 호출합니다. proxy ()를 사용하면 획득을 통해 대상 디바이스의 오브젝트를 원격으로 '관찰'할 수 있지만, 디바이스의 로컬:* 네트워크에서 대상을 벗어난 소스 오브젝트를 획득할 수는 없습니다. 이것이 바로 reverseProxy()가 필요한 이유입니다. 이렇게 proxyNode가 생성되면:
// myInternalHost is a node only visible on the device... QRemoteObjectHost myInternalHost("local:MyHost", "local:registry"); // RegistryHost node, listening on port 12123, so visible to other // devices. The node must be a RegistryHost, so the Sources on // the "outside" network can be forwarded to the inner network. QRemoteObjectRegistryHost proxyNode("tcp://0.0.0.0:12123"); // Enable proxying objects from nodes on the local machine's internal // QtRO bus. Note the hostUrl parameter is now needed. proxyNode.proxy("local:registry", "local:fromProxy"); proxyNode.reverseProxy();
그리고 다른 디바이스에서 또 다른 노드를 생성합니다:
// Listen on a local port, and connect to "proxyNode" as the registry. // NB: localhost resolves to a different ip address than proxyNode QRemoteObjectHost nodeOnRemoteDevice("tcp://localhost:23234", "tcp://<target device>:12123"); // Because of the reverseProxy, we can expose objects on this device // and they will make their way to proxyNode... nodeOnRemoteDevice.enableRemoting<OtherObject>(&otherObject);
// Acquire() can now see the objects on other devices through proxyNode, // due to the reverseProxy call. OtherObject *oo = myInternalHost.acquire<OtherObject>();
proxy() 기능을 사용하면 다른 네트워크의 소스 개체를 획득()할 수 있는 반면, reverseProxy()를 사용하면 소스 개체를 다른 네트워크에 액세스할 수 없는 네트워크로 "푸시"할 수 있습니다.
참고: proxy()는 reverseProxy() 전에 호출해야 하며, reverseProxy()가 작동하려면 proxy 에 hostUrl을 제공해야 합니다. reverseProxy() 메서드를 사용하면 별도의 filter 을 적용할 수 있습니다. 이 reverseProxy 전용 필터는 proxyNode
에서 새 Source 객체에 대한 알림을 수신하고 filter 을 통과하면 내부 노드에서 해당 객체를 획득합니다.
성공하면 true
, 그렇지 않으면 false
을 반환합니다.
참고: 현재 역방향 프록시 기능은 QRemoteObjectRegistryHost 에 대해서만 지원됩니다. QRemoteObjectHost 노드에서 이 메서드를 호출하면 항상 false
을 반환합니다.
proxy()도 참조하세요 .
[override virtual]
void QRemoteObjectHostBase::setName(const QString &name)
재구현합니다: QRemoteObjectNode::setName(const QString &name).
이 메서드가 호출하는 QObject::setObjectName()와 유사하지만, 이 버전은 일부 디버깅 출력에 사용되는 내부 클래스에도 name 을 적용합니다.
© 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.