Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

How to ignore ssl errors to get https website work on QML Webview

From Wiki
Jump to: navigation, search

This article explains how to ignore SSL errors to get https website's work on QML Webview

Article Metadata
Tested withCompatibility
Platform(s): All platforms with Qt 4.7 and later
Device(s): All
Keywords: QNetworkAccessManager, QDeclarativeEngine
Created: gaba88 (12 Jan 2012)
Last edited: hamishwillee (11 Oct 2012)


Exact Problem

Many of our day to day application development requires us to use QML Webview and open some https website for transferring some secured content, in some most of the Symbian^3 devices, there's a problem with this activity.

Most of the times QML Webview fires onLoadFailed signal whenever we try to open any of the https based website. For example this link is used during implementing OAuth to access the services of, but everytime you try to open this url in QML Webview it will always give you an onLoadFailed error.

Exact Reason

The main reason behind the behavior mentioned above is the missing or invalid certificate on the symbian^3 device which causes SSL error, hence QML Webview fires the onLoadFailed signal.


This code snippet will explain how to tackle the situation explained above. The problem is solved by simply bypassing the warnings which are caused due to the missing SSL certificate. This can be done by providing our own custom QNetworkAccessManager to the QML Declarative Engine which ignores the SSL errors.

Code Snippet

Following class explains how we can create our own QNetworkAccessManager, and how we can make the QDeclarativeEngine to use that QNetworkAccessManager. Apart from this our own QNetworkAccessManager also takes care of ignoring the SSL errors.


#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QSslError>
// need to derive your class from QDeclarativeNetworkAccessManagerFactory, Our class is derived also from QObject
// the reason is to use signal and slot mechanism
class CustomNetworkManagerFactory : public QObject,public QDeclarativeNetworkAccessManagerFactory
explicit CustomNetworkManagerFactory(QObject *parent = 0);
virtual QNetworkAccessManager *create(QObject *parent);
public slots:
void onIgnoreSSLErrors(QNetworkReply* reply,QList<QSslError> error);
QNetworkAccessManager* m_networkManager;


#include "customnetworkmanagerfactory.h"
CustomNetworkManagerFactory::CustomNetworkManagerFactory(QObject *parent) :
// nothing to be done on the constructor
this is a virtual method we need to implement this method , most important step
we will create our custom QNetworkAccessManager here and return that
the second important thing we need to do here is to connect the sslErrors signal from QNetworkAccessManager to our own slot
which will ignore the sslErrors

QNetworkAccessManager* CustomNetworkManagerFactory::create(QObject *parent)
m_networkManager = new QNetworkAccessManager(this);
return m_networkManager;
Our own slot which is connected to the sslErrors signal of QNetworkAccessManager
When this slot is called using the QNetworkReply object in the parameter we need to call ignoreSslErrors method of QNetworkReply

void CustomNetworkManagerFactory::onIgnoreSSLErrors(QNetworkReply *reply, QList<QSslError> error)

Once this class is complete we need to make sure that the QDeclarativeEngine uses the custom QDeclarativeNetworkAccessManagerFactory which we have designed above. To do that, please check the implementation of the main.cpp file as shown below:

#include "customnetworkmanagerfactory.h"
int main(int argc, char *argv[])
QApplication app(argc, argv);
// declare and intialize your custom network manager factory
CustomNetworkManagerFactory* myNetworkAccessManagerFactory = new CustomNetworkManagerFactory(&app);
// QDeclarativeEngine Interface provided by application template
QmlApplicationViewer viewer;
//set our customnetworkmanagerfactory on the declarative engine
return app.exec();

Once the developer successfully completes this then opening https websites will not be a problem.


This code snippet helps developer to understand the problem with SSL websites and QML webview on Symbian^3 devices and helps them to bypass the SSL errors by implementing our own custom QNetworkAccessManager and passing that to QDeclarativeEngine of QML.

This page was last modified on 11 October 2012, at 01:17.
191 page views in the last 30 days.