summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorGerhard Gappmeier <gerhard.gappmeier@ascolab.com>2018-11-13 10:30:04 +0100
committerJannis Völker <jannis.voelker@basyskom.com>2019-01-11 13:46:12 +0000
commit95ceb8788a954044b95fc0b9357950f76852d84a (patch)
treefb055fed890cb64f8508483d2f0b48a9df88768f /examples
parent7a4d1b45a47c7c179d0424903e423290371b79a2 (diff)
opcuaviewer: Implement connectError callback and add error dialog
Change-Id: I20c34cf47db2f0ea5873616436e045fb6c093448 Reviewed-by: Rainer Keller <Rainer.Keller@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/opcua/opcuaviewer/mainwindow.cpp43
-rw-r--r--examples/opcua/opcuaviewer/mainwindow.h1
2 files changed, 44 insertions, 0 deletions
diff --git a/examples/opcua/opcuaviewer/mainwindow.cpp b/examples/opcua/opcuaviewer/mainwindow.cpp
index 654243f..8c6bf69 100644
--- a/examples/opcua/opcuaviewer/mainwindow.cpp
+++ b/examples/opcua/opcuaviewer/mainwindow.cpp
@@ -67,6 +67,7 @@
#include <QHeaderView>
#include <QOpcUaProvider>
#include <QOpcUaAuthenticationInformation>
+#include <QOpcUaErrorState>
QT_BEGIN_NAMESPACE
@@ -214,6 +215,7 @@ void MainWindow::createClient()
return;
}
+ connect(mOpcUaClient, &QOpcUaClient::connectError, this, &MainWindow::showErrorDialog);
mOpcUaClient->setIdentity(m_identity);
mOpcUaClient->setPkiConfiguration(m_pkiConfig);
@@ -432,4 +434,45 @@ bool MainWindow::createPkiFolders()
return result;
}
+void MainWindow::showErrorDialog(QOpcUaErrorState *errorState)
+{
+ QString msg;
+ QMessageBox::StandardButtons buttons = QMessageBox::Ok;
+ QMessageBox::StandardButton defaultButton = QMessageBox::Ok;
+
+ const QString statuscode = QOpcUa::statusToString(errorState->errorCode());
+
+ if (errorState->isClientSideError())
+ msg = tr("The client reported: ");
+ else
+ msg = tr("The server reported: ");
+
+ switch (errorState->connectionStep()) {
+ case QOpcUaErrorState::ConnectionStep::CertificateValidation:
+ msg += tr("Server certificate validation failed with error 0x%1 (%2).\nClick 'Abort' to abort the connect, or 'Ignore' to continue connecting.")
+ .arg(static_cast<ulong>(errorState->errorCode()), 8, 16, QLatin1Char('0')).arg(statuscode);
+ buttons = QMessageBox::Ignore | QMessageBox::Abort;
+ defaultButton = QMessageBox::Abort;
+ break;
+ case QOpcUaErrorState::ConnectionStep::OpenSecureChannel:
+ msg += tr("OpenSecureChannel failed with error 0x%1 (%2).").arg(errorState->errorCode(), 8, 16, QLatin1Char('0')).arg(statuscode);
+ break;
+ case QOpcUaErrorState::ConnectionStep::CreateSession:
+ msg += tr("CreateSession failed with error 0x%1 (%2).").arg(errorState->errorCode(), 8, 16, QLatin1Char('0')).arg(statuscode);
+ break;
+ case QOpcUaErrorState::ConnectionStep::ActivateSession:
+ msg += tr("ActivateSession failed with error 0x%1 (%2).").arg(errorState->errorCode(), 8, 16, QLatin1Char('0')).arg(statuscode);
+ break;
+ }
+
+ QMessageBox::StandardButton result = QMessageBox::warning(
+ this,
+ tr("Connect Error"),
+ msg,
+ buttons,
+ defaultButton);
+
+ errorState->setIgnoreError(result == QMessageBox::Ignore);
+}
+
QT_END_NAMESPACE
diff --git a/examples/opcua/opcuaviewer/mainwindow.h b/examples/opcua/opcuaviewer/mainwindow.h
index ac776d2..80e7c64 100644
--- a/examples/opcua/opcuaviewer/mainwindow.h
+++ b/examples/opcua/opcuaviewer/mainwindow.h
@@ -82,6 +82,7 @@ private slots:
void clientDisconnected();
void clientError(QOpcUaClient::ClientError);
void clientState(QOpcUaClient::ClientState);
+ void showErrorDialog(QOpcUaErrorState *errorState);
private:
void createClient();