From 699f772bffab3ae0a6399f56d7154e333a273d6c Mon Sep 17 00:00:00 2001 From: Kurt Pattyn <pattyn.kurt@gmail.com> Date: Wed, 12 Mar 2014 11:23:24 +0100 Subject: [PATCH] Fix for self-signed certificates Change-Id: I529976e6fc8813d273290e97e86405f51c3efa57 Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com> --- examples/sslechoclient/sslechoclient.cpp | 12 ++++++++++++ examples/sslechoclient/sslechoclient.h | 9 +++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/examples/sslechoclient/sslechoclient.cpp b/examples/sslechoclient/sslechoclient.cpp index fdf00df7..cf5b9764 100644 --- a/examples/sslechoclient/sslechoclient.cpp +++ b/examples/sslechoclient/sslechoclient.cpp @@ -40,6 +40,8 @@ ****************************************************************************/ #include "sslechoclient.h" #include <QtCore/QDebug> +#include <QtWebSockets/QWebSocket> +#include <QCoreApplication> QT_USE_NAMESPACE @@ -49,6 +51,9 @@ SslEchoClient::SslEchoClient(const QUrl &url, QObject *parent) : m_webSocket() { connect(&m_webSocket, &QWebSocket::connected, this, &SslEchoClient::onConnected); + typedef void (QWebSocket:: *sslErrorsSignal)(const QList<QSslError> &); + connect(&m_webSocket, static_cast<sslErrorsSignal>(&QWebSocket::sslErrors), + this, &SslEchoClient::onSslErrors); m_webSocket.open(QUrl(url)); } //! [constructor] @@ -67,5 +72,12 @@ void SslEchoClient::onConnected() void SslEchoClient::onTextMessageReceived(QString message) { qDebug() << "Message received:" << message; + qApp->quit(); +} + +void SslEchoClient::onSslErrors(const QList<QSslError> &errors) +{ + Q_UNUSED(errors); + m_webSocket.ignoreSslErrors(); } //! [onTextMessageReceived] diff --git a/examples/sslechoclient/sslechoclient.h b/examples/sslechoclient/sslechoclient.h index cec9e9d0..7ec373b9 100644 --- a/examples/sslechoclient/sslechoclient.h +++ b/examples/sslechoclient/sslechoclient.h @@ -43,6 +43,10 @@ #include <QtCore/QObject> #include <QtWebSockets/QWebSocket> +#include <QtNetwork/QSslError> +#include <QtCore/QList> +#include <QtCore/QString> +#include <QtCore/QUrl> QT_FORWARD_DECLARE_CLASS(QWebSocket) @@ -52,13 +56,10 @@ class SslEchoClient : public QObject public: explicit SslEchoClient(const QUrl &url, QObject *parent = Q_NULLPTR); -Q_SIGNALS: - -public Q_SLOTS: - private Q_SLOTS: void onConnected(); void onTextMessageReceived(QString message); + void onSslErrors(const QList<QSslError> &errors); private: QWebSocket m_webSocket; -- GitLab