Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Qml image SSL error

    QML and Qt Quick
    ssl qml network
    2
    2
    1246
    Loading More Posts
    • 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.
    • Mkowalik-Mimesis
      Mkowalik-Mimesis last edited by Mkowalik-Mimesis

      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);
      
          ...
      }
      
      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @Mkowalik-Mimesis last edited by raven-worx

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

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 1
        • First post
          Last post