Fix for self-signed certificates
authorKurt Pattyn <pattyn.kurt@gmail.com>
Wed, 12 Mar 2014 10:23:24 +0000 (11:23 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 12 Mar 2014 10:45:34 +0000 (11:45 +0100)
Change-Id: I529976e6fc8813d273290e97e86405f51c3efa57
Reviewed-by: Kurt Pattyn <pattyn.kurt@gmail.com>
examples/sslechoclient/sslechoclient.cpp
examples/sslechoclient/sslechoclient.h

index fdf00df..cf5b976 100644 (file)
@@ -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]
index cec9e9d..7ec373b 100644 (file)
 
 #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;