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:

    customnetworkmanagerfactory.h

    #include <QObject>
    #include <QNetworkAccessManager>
    #include <QNetworkReply>
    #include <QSslError>
    #include <QQmlNetworkAccessManagerFactory>
    
    class CustomNetworkManagerFactory : public QObject,
            public QQmlNetworkAccessManagerFactory
    {
        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;
    };
    

    customnetworkmanagerfactory.cpp

    #include "customnetworkmanagerfactory.h"
    
    CustomNetworkManagerFactory::CustomNetworkManagerFactory(QObject *parent) :
        QObject(parent)
    {
    }
    
    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;
    }
    
    void CustomNetworkManagerFactory::onIgnoreSSLErrors(QNetworkReply *reply, QList<QSslError> error)
    {
        reply->ignoreSslErrors(error);  //<-- CRASH HERE
    }
    

    main.cpp

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

  • Moderators

    @Mkowalik-Mimesis
    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
 

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