Ignoring SSL errors



  • Hi,
    I use the code from http://www.developer.nokia.com/Community/Wiki/How_to_ignore_ssl_errors_to_get_https_website_work_on_QML_Webview

    I edited it like this:

    main.cpp
    @
    #include <QtGui/QApplication>
    #include "customnetworkmanagerfactory.h"
    #include "qmlapplicationviewer.h"
    #include <QDeclarativeEngine>

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QmlApplicationViewer viewer;
    CustomNetworkManagerFactory* myNetworkAccessManagerFactory = new CustomNetworkManagerFactory(&app);
    viewer.engine()->setNetworkAccessManagerFactory(myNetworkAccessManagerFactory);
    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer.setMainQmlFile&#40;QLatin1String("qml/YouTube/main.qml"&#41;);
    viewer.showExpanded();
    
    return app.exec&#40;&#41;;
    

    }

    @

    networkaccessmanager.h
    @
    #include <QObject>
    #include <QtNetwork/QNetworkAccessManager>
    #include <QtNetwork/QNetworkReply>
    #include <QtNetwork/QSslError>
    #include <QDeclarativeNetworkAccessManagerFactory>

    // 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
    {
    Q_OBJECT
    public:
    explicit CustomNetworkManagerFactory(QObject *parent = 0);
    virtual QNetworkAccessManager *create(QObject *parent);

    public slots:
    void onIgnoreSSLErrors(QNetworkReply* reply,QList<QSslError> error);

    private:
    QNetworkAccessManager* m_networkManager;

    };
    @

    networkaccessmanager.cpp
    @
    #include "networkaccessmanager.h"

    CustomNetworkManagerFactory::CustomNetworkManagerFactory(QObject *parent) :
    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);
    connect(m_networkManager,SIGNAL(sslErrors(QNetworkReply
    ,QList<QSslError>)),this,SLOT(onIgnoreSSLErrors(QNetworkReply*,QList<QSslError>)));

    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)
    {
    reply->ignoreSslErrors(error);
    }
    @

    I get these errors:
    !http://s17.postimage.org/g3drb8hbj/image.png(errors)!


  • Moderators

    Did it compile and link properly on this machine before you changed the code?



  • No, it did not. I needed to edit and add include links.
    I added #include <QDeclarativeEngine> and #include <QDeclarativeNetworkAccessManagerFactory>.
    I edited network links (needed to add <QtNetwork/xxxx before).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.