Important: Please read the Qt Code of Conduct -

Qml image SSL error

  • Hello,

    I have problem with QML loading images from server with SSL. I tried to use custom QQmlNetworkAccessManagerFactory and ignore SSL errors but I have crash on QNetworkReply::ignoreSslErrors(QList<QSslError> errors).

    Here is my code:


    #include <QObject>
    #include <QNetworkAccessManager>
    #include <QNetworkReply>
    #include <QSslError>
    #include <QQmlNetworkAccessManagerFactory>
    class CustomNetworkManagerFactory : public QObject,
            public QQmlNetworkAccessManagerFactory
        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) :
    QNetworkAccessManager* CustomNetworkManagerFactory::create(QObject *parent)
        m_networkManager = new QNetworkAccessManager(this);
        return m_networkManager;
    void CustomNetworkManagerFactory::onIgnoreSSLErrors(QNetworkReply *reply, QList<QSslError> error)
        reply->ignoreSslErrors(error);  //<-- CRASH HERE


    int main(int argc, char *argv[])
        QGuiApplication app(argc, argv);
        QQmlApplicationEngine engine;
        CustomNetworkManagerFactory qmlFactory(&engine);

  • Moderators

    and why does it crash?
    What is the value of incoming QNetworkReply* ?
    Are you doing any fancy deletes?

    1. in your CustomNetworkManagerFactory::create() you get a QObject* passed as a parent for the QNAM to create. But you set the parent to the this pointer instead.
    2. it would be cleaner not to couple the created QNAM with your factory class by connecting signals and slots of them. Instead you should subclass QNAM, move the onIgnoreSSLErrors() slot to it and connect it to itself instead.
    3. you are overwriting your local m_networkManager member variable everytime create() is called. Which doesn't go along with a factory implementation ;)

    I don't know if this already solves your crash, it may be.

Log in to reply