QOpcUaGdsClient Class
负责与GDS服务器进行通信。更多内容...
| 标题: | #include <QOpcUaGdsClient> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS OpcUa) target_link_libraries(mytarget PRIVATE Qt6::OpcUa) |
| qmake: | QT += opcua |
| 继承自: | QObject |
公共类型
| enum class | Error { NoError, InvalidBackend, InvalidEndpoint, ConnectionError, DirectoryNodeNotFound, …, FailedToGetCertificate } |
| enum class | State { Idle, BackendInstantiated, Connecting, Connected, RegisteringApplication, …, Error } |
公共函数
| QOpcUaGdsClient(QObject *parent = nullptr) | |
| virtual | ~QOpcUaGdsClient() |
| QString | applicationId() const |
| const QOpcUaApplicationIdentity & | applicationIdentity() const |
| const QOpcUaApplicationRecordDataType & | applicationRecord() const |
| const QString & | backend() const |
| int | certificateCheckInterval() const |
| const QOpcUaX509DistinguishedName & | distinguishedNameCertificateSigningRequestPreset() const |
| const QString & | dnsCertificateSigningRequestPreset() const |
| const QOpcUaEndpointDescription & | endpoint() const |
| QOpcUaGdsClient::Error | error() const |
| const QOpcUaPkiConfiguration & | pkiConfiguration() const |
| void | setApplicationIdentity(const QOpcUaApplicationIdentity &appIdentity) |
| void | setApplicationRecord(const QOpcUaApplicationRecordDataType &appRecord) |
| void | setBackend(const QString &backend) |
| void | setCertificateCheckInterval(int interval) |
| void | setCertificateSigningRequestPresets(const QOpcUaX509DistinguishedName &dn, const QString &dns) |
| void | setEndpoint(const QOpcUaEndpointDescription &endpoint) |
| void | setPkiConfiguration(const QOpcUaPkiConfiguration &pkiConfig) |
| void | setTrustListUpdateInterval(int interval) |
| void | start() |
| QOpcUaGdsClient::State | state() const |
| int | trustListUpdateInterval() const |
| void | unregisterApplication() |
信号
| void | applicationRegistered() |
| void | authenticationRequired(QOpcUaAuthenticationInformation &authInfo) |
| void | certificateGroupsReceived(QStringList certificateGroups) |
| void | certificateUpdateRequired() |
| void | certificateUpdated() |
| void | errorChanged(QOpcUaGdsClient::Error error) |
| void | stateChanged(QOpcUaGdsClient::State state) |
| void | trustListUpdated() |
| void | unregistered() |
详细说明
该类目前处于“技术预览”阶段,因此该类提供的 API 和功能可能会随时发生变更,恕不另行通知。
该类负责处理与GDS服务器通信所需的所有步骤。在获得应用程序相关信息后,它会向服务器进行注册并管理密钥/证书。
只需了解少量细节,即可加入安全网络。
首次注册需要管理员权限,并使用用户名和密码进行身份验证。此后所有身份验证均基于应用程序,使用最初获取的证书。
若希望整个过程成功,您需要等待applicationRegistered 信号。
大多数配置结构必须与后续连接QOpcUaClient 时的配置结构保持一致,且可以复用。
配置 GDS 客户端:
QOpcUaGdsClient c;
// 若需凭据
QObject::connect(&c, &QOpcUaGdsClient::authenticationRequired, [&](QOpcUaAuthenticationInformation&authInfo) {
authInfo.setUsernameAuthentication("root", "secret");
});
// 等待连接成功
QObject::connect(&c, &QOpcUaGdsClient::applicationRegistered, [&]() {
qDebug() << "Application" << c.applicationId() << "registered";
});
c.setBackend(...);
c.setEndpoint(...);
c.setApplicationIdentity(...);
c.setPkiConfiguration(...);
c.setApplicationRecord(...);
c.setCertificateSigningRequestPresets(...);
c.start();成员类型文档
enum class QOpcUaGdsClient::Error
此枚举用于指定注册过程中可能出现的错误。
| 常量 | 值 | 描述 |
|---|---|---|
QOpcUaGdsClient::Error::NoError | 0 | 一切正常 |
QOpcUaGdsClient::Error::InvalidBackend | 1 | 无法实例化后端。给定的后端字符串与任何后端都不匹配,或者加载插件失败。 |
QOpcUaGdsClient::Error::InvalidEndpoint | 2 | 给定的端点无效。 |
QOpcUaGdsClient::Error::ConnectionError | 3 | 连接到服务器端点的请求失败。 |
QOpcUaGdsClient::Error::DirectoryNodeNotFound | 4 | 无法解析服务器上的目录节点 |
QOpcUaGdsClient::Error::FailedToRegisterApplication | 5 | 应用程序注册未成功。 |
QOpcUaGdsClient::Error::FailedToUnregisterApplication | 6 | 应用程序注销失败。 |
QOpcUaGdsClient::Error::FailedToGetCertificateStatus | 7 | 无法检索到当前证书的状态。 |
QOpcUaGdsClient::Error::FailedToGetCertificate | 8 | 无法从服务器检索到证书。 |
enum class QOpcUaGdsClient::State
此枚举用于指定 GDS 客户端注册的当前状态。
| 常量 | 值 | 描述 |
|---|---|---|
QOpcUaGdsClient::State::Idle | 0 | 客户端尚未启动。 |
QOpcUaGdsClient::State::BackendInstantiated | 1 | 后端已实例化 |
QOpcUaGdsClient::State::Connecting | 2 | 正在连接服务器 |
QOpcUaGdsClient::State::Connected | 3 | 已成功连接到服务器端点。 |
QOpcUaGdsClient::State::RegisteringApplication | 4 | 正在向服务器注册应用程序。 |
QOpcUaGdsClient::State::ApplicationRegistered | 5 | 应用程序已在服务器上注册成功。 |
QOpcUaGdsClient::State::Error | 6 | 发生错误。请查看error()的返回值和终端输出以获取更多详细信息。 |
成员函数文档
QOpcUaGdsClient::QOpcUaGdsClient(QObject *parent = nullptr)
创建一个 GDS 客户端,其父对象为parent 。
[virtual noexcept] QOpcUaGdsClient::~QOpcUaGdsClient()
销毁一个 GDS 客户端。
QString QOpcUaGdsClient::applicationId() const
返回服务器分配的应用程序 ID。
这是从应用程序记录数据中获取应用程序 ID 的快捷方式。
另请参阅 applicationRecord()。
const QOpcUaApplicationIdentity &QOpcUaGdsClient::applicationIdentity() const
返回当前的 applicationIdentity。
另请参阅 setApplicationIdentity()。
const QOpcUaApplicationRecordDataType &QOpcUaGdsClient::applicationRecord() const
返回客户端使用的应用程序记录数据。
另请参阅 setApplicationRecord()。
[signal] void QOpcUaGdsClient::applicationRegistered()
当应用程序注册成功时,会发出此信号。
[signal] void QOpcUaGdsClient::authenticationRequired(QOpcUaAuthenticationInformation &authInfo)
当 GDS 客户端尝试与需要管理员权限的服务器进行首次身份验证时,会发出此信号。
authInfo 必须填入有效的身份验证信息。该字段不得用于跨线程操作。
const QString &QOpcUaGdsClient::backend() const
返回当前的后端设置。
如果客户端启动后后端被更改,则该函数将返回已更改的设置,而非实际使用的实例。
另请参阅 setBackend()。
int QOpcUaGdsClient::certificateCheckInterval() const
返回用于检查客户端证书有效性的时间间隔(以毫秒为单位)。
另请参阅 setCertificateCheckInterval()。
[signal] void QOpcUaGdsClient::certificateGroupsReceived(QStringList certificateGroups)
当 GDS 客户端收到该应用程序的新certificateGroups 列表时,会发出此信号。
[signal] void QOpcUaGdsClient::certificateUpdateRequired()
当 GDS 客户端检测到需要更新当前使用的证书时,会发出此信号。
这可能是由于服务器要求客户端更新证书所致,例如当证书到期或证书为自签名证书时。
证书更新将自动处理。此信号仅用于通知即将发生更新,仅供参考。
[signal] void QOpcUaGdsClient::certificateUpdated()
当 GDS 客户端收到存储在磁盘上的一份新证书时,会发出此信号。
const QOpcUaX509DistinguishedName &QOpcUaGdsClient::distinguishedNameCertificateSigningRequestPreset() const
返回证书签名请求中预设的区分名称。
const QString &QOpcUaGdsClient::dnsCertificateSigningRequestPreset() const
返回证书签名请求的 DNS 预设。
const QOpcUaEndpointDescription &QOpcUaGdsClient::endpoint() const
返回当前的端点设置。
如果客户端启动后端点被修改,该方法将返回已修改的设置,而非实际使用的端点。
另请参阅 setEndpoint()。
QOpcUaGdsClient::Error QOpcUaGdsClient::error() const
返回当前的错误状态。
[signal] void QOpcUaGdsClient::errorChanged(QOpcUaGdsClient::Error error)
当发生error 时,会发出此信号。
const QOpcUaPkiConfiguration &QOpcUaGdsClient::pkiConfiguration() const
返回当前的 pkiConfiguration。
另请参阅 setPkiConfiguration()。
void QOpcUaGdsClient::setApplicationIdentity(const QOpcUaApplicationIdentity &appIdentity)
设置客户端将使用的应用程序标识appIdentity 。
该标识用于向 GDS 服务器进行注册。必须在启动 GDS 客户端之前调用此函数。此后更改此设置将无效。
另请参阅 applicationIdentity()。
void QOpcUaGdsClient::setApplicationRecord(const QOpcUaApplicationRecordDataType &appRecord)
设置客户端将使用的应用程序记录数据appRecord 。
该数据用于向 GDS 服务器进行注册。必须在启动 GDS 客户端之前调用此函数。
其中大部分数据与应用程序标识中的数据相同。注册完成后,可获取分配的应用程序 ID。
另请参阅 applicationRecord() 和setApplicationIdentity 。
void QOpcUaGdsClient::setBackend(const QString &backend)
将客户端用于与服务器通信的后端设置为backend 。
必须在启动 GDS 客户端之前调用此函数。此后更改此设置将无效。
另请参阅 backend()、QOpcUaProvider::availableBackends() 以及start()。
void QOpcUaGdsClient::setCertificateCheckInterval(int interval)
将检查客户端证书有效性的间隔(以毫秒为单位)设置为interval 。
另请参阅 certificateCheckInterval()。
void QOpcUaGdsClient::setCertificateSigningRequestPresets(const QOpcUaX509DistinguishedName &dn, const QString &dns)
设置证书签名请求的预设值:区分名称dn 和 DNS 字符串dns 。
在创建证书签名请求时,需要一些应用程序标识未提供的额外信息。
必须在启动 GDS 客户端之前调用此函数。
另请参阅 setApplicationIdentity()。
void QOpcUaGdsClient::setEndpoint(const QOpcUaEndpointDescription &endpoint)
将客户端用于与服务器通信的端点设置为endpoint 。
必须在启动 GDS 客户端之前调用此函数。事后更改此设置将无效。
仅可通过加密端点与 GDS 服务器进行通信。使用未加密的端点将导致通信失败。
另请参阅 endpoint()。
void QOpcUaGdsClient::setPkiConfiguration(const QOpcUaPkiConfiguration &pkiConfig)
设置客户端将使用的 PKI 配置pkiConfig 。
所有证书、密钥和信任列表都将从指定位置获取或存储至指定位置。若要使用从 GDS 接收的证书,必须在QOpcUaClient 中使用相同的配置。
必须在启动 GDS 客户端之前调用此函数。事后更改此设置将无效。
另请参阅 pkiConfiguration()。
void QOpcUaGdsClient::setTrustListUpdateInterval(int interval)
设置服务器向interval 更新信任列表的间隔(单位为毫秒)。
另请参阅 trustListUpdateInterval()。
void QOpcUaGdsClient::start()
启动客户端进程。
配置完所有信息后,即可启动客户端。
- setBackend
- setEndpoint
- setApplicationIdentity
- setPkiConfiguration
- setApplicationRecord
- setCertificateSigningRequestPresets
QOpcUaGdsClient::State QOpcUaGdsClient::state() const
返回当前客户端状态。
[signal] void QOpcUaGdsClient::stateChanged(QOpcUaGdsClient::State state)
当客户端的内部状态发生变化时,会发出此信号。state 指示新的状态。
int QOpcUaGdsClient::trustListUpdateInterval() const
返回从服务器更新信任列表的时间间隔(以毫秒为单位)。
另请参阅 setTrustListUpdateInterval()。
[signal] void QOpcUaGdsClient::trustListUpdated()
当 GDS 客户端从服务器接收到了新的信任列表并将其存储到磁盘时,会发出此信号。
void QOpcUaGdsClient::unregisterApplication()
从服务器上注销应用程序。
当需要将应用程序永久从网络中移除时,可使用此函数。在重启或关机时无需调用此函数。
[signal] void QOpcUaGdsClient::unregistered()
当 GDS 客户端已注销该应用程序时,会发出此信号。
© 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.