Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Ignoring SSL errors
Forum Updated to NodeBB v4.3 + New Features

Ignoring SSL errors

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 5.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    michprev
    wrote on last edited by
    #1

    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)!

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

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

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        michprev
        wrote on last edited by
        #3

        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).

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved